Skip to content

Commit

Permalink
Deprecation warnings for old syntax: with as a type operator (#18837)
Browse files Browse the repository at this point in the history
This is the first part of #18868
  • Loading branch information
nicolasstucki authored Nov 9, 2023
2 parents e292303 + 61917a6 commit a90db4f
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ object projects:
project = "zio",
sbtTestCommand = "testJVMDotty",
sbtDocCommand = forceDoc("coreJVM"),
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Xcheck-macros"),
scalacOptions = "-source" :: "3.3" :: SbtCommunityProject.scalacOptions.filter(_ != "-Xcheck-macros"),
dependencies =List(izumiReflect)
)

Expand Down
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1757,11 +1757,12 @@ object Parsers {
t
else
val withSpan = Span(withOffset, withOffset + 4)
report.errorOrMigrationWarning(
DeprecatedWithOperator(rewriteNotice(`future-migration`)),
report.gradualErrorOrMigrationWarning(
DeprecatedWithOperator(rewriteNotice(`3.4-migration`)),
source.atSpan(withSpan),
from = future)
if sourceVersion == `future-migration` then
warnFrom = `3.4`,
errorFrom = future)
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
patch(source, withSpan, "&")
atSpan(startOffset(t)) { makeAndType(t, withType()) }
else t
Expand Down
9 changes: 7 additions & 2 deletions compiler/test-resources/repl/i6643
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
scala> import scala.collection._

scala>:type 1
Int

scala> object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
// defined object IterableTest
21 changes: 21 additions & 0 deletions compiler/test-resources/type-printer/infix
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,31 @@ def foo: Int && Boolean & String
scala> def foo: Int && (Boolean & String) = ???
def foo: Int && (Boolean & String)
scala> def foo: Int && (Boolean with String) = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: Int && (Boolean with String) = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && (Boolean & String)
scala> def foo: (Int && Boolean) with String = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: (Int && Boolean) with String = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && Boolean & String
scala> def foo: Int && Boolean with String = ???
1 warning found
-- [E003] Syntax Warning: ------------------------------------------------------
1 | def foo: Int && Boolean with String = ???
| ^^^^
| with as a type operator has been deprecated; use & instead
|
| longer explanation available when compiling with `-explain`
def foo: Int && (Boolean & String)
scala> def foo: Int && Boolean | String = ???
def foo: Int && Boolean | String
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-scalajs/js-native-members.check
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
| The [this] qualifier will be deprecated in the future; it should be dropped.
| See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
-- [E003] Syntax Warning: tests/neg-scalajs/js-native-members.scala:58:44 ----------------------------------------------
58 | def assign[T, U](target: T, source: U): T with U = js.native // ok
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/js-native-members.scala:9:24 ---------------------------------------------------------------
9 | def this(z: String) = this(z.length, z) // error
| ^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 14 additions & 0 deletions tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:41 -------------------------
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:35 -------------------------
22 | val g = js.constructorOf[JSClass with JSTrait] // error
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:13:27 -----------------------------------------
13 | val a = js.constructorOf[NativeJSTrait] // error
| ^^^^^^^^^^^^^
Expand Down
14 changes: 14 additions & 0 deletions tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:42 ------------------------
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:36 ------------------------
22 | val g = js.constructorTag[JSClass with JSTrait] // error
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:13:42 ----------------------------------------
13 | val a = js.constructorTag[NativeJSTrait] // error
| ^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i2887b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trait C { type M <: B }
trait D { type M >: A }

object Test {
def test(x: C with D): Unit = {
def test(x: C & D): Unit = {
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z
def bar(a: A, y: x.M) = foo(a,y)
def baz(a: A) = bar(a, a)
Expand Down
6 changes: 3 additions & 3 deletions tests/neg/i8736.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ object App extends App {
def field[V](s: String)(v: V): Rec[s.type, V] = Rec0(Map(s -> v)).asInstanceOf[Rec[s.type, V]]

implicit class RecOps[R <: Rec0[_]](has: R) {
def +[K1 <: String, V1](that: Rec[K1, V1]): R with Rec[K1, V1] = Rec0(has.map ++ that.map).asInstanceOf[R with Rec[K1, V1]]
def +[K1 <: String, V1](that: Rec[K1, V1]): R & Rec[K1, V1] = Rec0(has.map ++ that.map).asInstanceOf[R & Rec[K1, V1]]
}

def rec:
Rec["k", String]
with Rec["v", Int]
with Rec["z", Boolean]
& Rec["v", Int]
& Rec["z", Boolean]
= {
field("k")("Str") +
field("v")(0) +
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/with-type-operator-future-migration.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
5 |def foo: Int with String = ??? // error
| ^^^^
| with as a type operator has been deprecated; use & instead
| This construct can be rewritten automatically under -rewrite -source future-migration.
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
|
| longer explanation available when compiling with `-explain`
4 changes: 3 additions & 1 deletion tests/pos-deep-subtype/3324h.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//> using options -Xfatal-warnings

import scala.language.`3.3`

object Test {
trait Marker
def foo[T](x: T) = x match {
Expand All @@ -8,7 +10,7 @@ object Test {
}

def foo2[T](x: T) = x match {
case _: T with Marker => // scalac emits a warning
case _: T with Marker => // scalac or 3.4 emits a warning
case _ =>
}
}
5 changes: 5 additions & 0 deletions tests/pos/with-type-operator-3.3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//> using options -Werror

import scala.language.`3.3`

def foo: Int with String = ???
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//> using options -Werror
import scala.language.`3.4-migration`

def foo: Int with String = ??? // warn
3 changes: 0 additions & 3 deletions tests/pos/with-type-operator-future-migration.scala

This file was deleted.

11 changes: 10 additions & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3394,6 +3394,7 @@ Text => empty
Language => Scala
Symbols => 13 entries
Occurrences => 22 entries
Diagnostics => 1 entries

Symbols:
local0 => selfparam self: C1
Expand Down Expand Up @@ -3434,6 +3435,10 @@ Occurrences:
[13:17..13:17): <- selfs/C6#`<init>`().
[13:27..13:28): B -> selfs/B#

Diagnostics:
[10:29..10:33): [warning] with as a type operator has been deprecated; use & instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.

expect/StructuralTypes.scala
----------------------------

Expand Down Expand Up @@ -5059,7 +5064,7 @@ Text => empty
Language => Scala
Symbols => 143 entries
Occurrences => 246 entries
Diagnostics => 1 entries
Diagnostics => 3 entries
Synthetics => 1 entries

Symbols:
Expand Down Expand Up @@ -5457,6 +5462,10 @@ Occurrences:

Diagnostics:
[5:13..5:14): [warning] unused explicit parameter
[62:25..62:29): [warning] with as a type operator has been deprecated; use & instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[63:25..63:29): [warning] with as a type operator has been deprecated; use & instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.

Synthetics:
[68:20..68:24):@ann => *[Int]
Expand Down

0 comments on commit a90db4f

Please sign in to comment.