diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 41ba452fa80a..153100aa77ff 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -42,7 +42,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { /** mods object name impl */ case class ModuleDef(name: TermName, impl: Template)(implicit @constructorOnly src: SourceFile) extends MemberDef { - type ThisTree[+T <: Untyped] <: Trees.NameTree[T] with Trees.MemberDef[T] with ModuleDef + type ThisTree[+T <: Untyped] <: Trees.NameTree[T] & Trees.MemberDef[T] & ModuleDef def withName(name: Name)(using Context): ModuleDef = cpy.ModuleDef(this)(name.toTermName, impl) } diff --git a/compiler/src/dotty/tools/dotc/config/CliCommand.scala b/compiler/src/dotty/tools/dotc/config/CliCommand.scala index 914df040fbf7..64f1d63c61ca 100644 --- a/compiler/src/dotty/tools/dotc/config/CliCommand.scala +++ b/compiler/src/dotty/tools/dotc/config/CliCommand.scala @@ -12,7 +12,7 @@ import scala.PartialFunction.cond trait CliCommand: - type ConcreteSettings <: CommonScalaSettings with Settings.SettingGroup + type ConcreteSettings <: CommonScalaSettings & Settings.SettingGroup def versionMsg: String diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index c845ea8f74c7..f9e9b49f3440 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1756,12 +1756,14 @@ object Parsers { if in.token == LBRACE || in.token == INDENT then t else - report.errorOrMigrationWarning( - DeprecatedWithOperator(rewriteNotice(`future-migration`)), - in.sourcePos(withOffset), - from = future) - if sourceVersion == `future-migration` then - patch(source, Span(withOffset, withOffset + 4), "&") + val withSpan = Span(withOffset, withOffset + 4) + report.gradualErrorOrMigrationWarning( + DeprecatedWithOperator(rewriteNotice(`3.4-migration`)), + source.atSpan(withSpan), + warnFrom = `3.4`, + errorFrom = future) + if sourceVersion.isAtLeast(`3.4-migration`) then + patch(source, withSpan, "&") atSpan(startOffset(t)) { makeAndType(t, withType()) } else t diff --git a/compiler/test-resources/repl/i6643 b/compiler/test-resources/repl/i6643 index e139ae9f7f94..ff482d8ce5f1 100644 --- a/compiler/test-resources/repl/i6643 +++ b/compiler/test-resources/repl/i6643 @@ -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 diff --git a/compiler/test-resources/type-printer/infix b/compiler/test-resources/type-printer/infix index a7904ae9ec43..2fe2864ad9fe 100644 --- a/compiler/test-resources/type-printer/infix +++ b/compiler/test-resources/type-printer/infix @@ -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 diff --git a/tests/neg/i2887b.scala b/tests/neg/i2887b.scala index 649d869678cb..b41a392271e2 100644 --- a/tests/neg/i2887b.scala +++ b/tests/neg/i2887b.scala @@ -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) diff --git a/tests/neg/i8736.scala b/tests/neg/i8736.scala index dc2fa1821791..5c4b16fd1a1a 100644 --- a/tests/neg/i8736.scala +++ b/tests/neg/i8736.scala @@ -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 with 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) + diff --git a/tests/neg/with-type-operator-future-migration.check b/tests/neg/with-type-operator-future-migration.check index 29ea1d5aad4c..e56049880431 100644 --- a/tests/neg/with-type-operator-future-migration.check +++ b/tests/neg/with-type-operator-future-migration.check @@ -1,7 +1,7 @@ -- [E003] Syntax Error: tests/neg/with-type-operator-future-migration.scala:5:13 --------------------------------------- 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` diff --git a/tests/pos-deep-subtype/3324h.scala b/tests/pos-deep-subtype/3324h.scala index bff25ee3c888..6bae5f6a01d9 100644 --- a/tests/pos-deep-subtype/3324h.scala +++ b/tests/pos-deep-subtype/3324h.scala @@ -1,5 +1,7 @@ //> using options -Xfatal-warnings +import scala.language.`3.3` + object Test { trait Marker def foo[T](x: T) = x match { @@ -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 _ => } } diff --git a/tests/pos/with-type-operator-3.3.scala b/tests/pos/with-type-operator-3.3.scala new file mode 100644 index 000000000000..2b40939d71b0 --- /dev/null +++ b/tests/pos/with-type-operator-3.3.scala @@ -0,0 +1,5 @@ +//> using options -Werror + +import scala.language.`3.3` + +def foo: Int with String = ??? diff --git a/tests/pos/with-type-operator.scala b/tests/pos/with-type-operator-3.4-migration.scala similarity index 51% rename from tests/pos/with-type-operator.scala rename to tests/pos/with-type-operator-3.4-migration.scala index d1fa5e2c34b7..27761a5e4a7f 100644 --- a/tests/pos/with-type-operator.scala +++ b/tests/pos/with-type-operator-3.4-migration.scala @@ -1,3 +1,3 @@ -//> using options -Werror +import scala.language.`3.4-migration` def foo: Int with String = ??? // warn diff --git a/tests/pos/with-type-operator-future-migration.scala b/tests/pos/with-type-operator-future-migration.scala deleted file mode 100644 index d6fe5205fd3d..000000000000 --- a/tests/pos/with-type-operator-future-migration.scala +++ /dev/null @@ -1,3 +0,0 @@ -import scala.language.`future-migration` - -def foo: Int with String = ??? // warn