Skip to content

Commit a90db4f

Browse files
Deprecation warnings for old syntax: with as a type operator (#18837)
This is the first part of #18868
2 parents e292303 + 61917a6 commit a90db4f

15 files changed

+93
-18
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ object projects:
404404
project = "zio",
405405
sbtTestCommand = "testJVMDotty",
406406
sbtDocCommand = forceDoc("coreJVM"),
407-
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Xcheck-macros"),
407+
scalacOptions = "-source" :: "3.3" :: SbtCommunityProject.scalacOptions.filter(_ != "-Xcheck-macros"),
408408
dependencies =List(izumiReflect)
409409
)
410410

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -1757,11 +1757,12 @@ object Parsers {
17571757
t
17581758
else
17591759
val withSpan = Span(withOffset, withOffset + 4)
1760-
report.errorOrMigrationWarning(
1761-
DeprecatedWithOperator(rewriteNotice(`future-migration`)),
1760+
report.gradualErrorOrMigrationWarning(
1761+
DeprecatedWithOperator(rewriteNotice(`3.4-migration`)),
17621762
source.atSpan(withSpan),
1763-
from = future)
1764-
if sourceVersion == `future-migration` then
1763+
warnFrom = `3.4`,
1764+
errorFrom = future)
1765+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
17651766
patch(source, withSpan, "&")
17661767
atSpan(startOffset(t)) { makeAndType(t, withType()) }
17671768
else t

compiler/test-resources/repl/i6643

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
scala> import scala.collection._
2-
32
scala>:type 1
43
Int
5-
64
scala> object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
5+
1 warning found
6+
-- [E003] Syntax Warning: ------------------------------------------------------
7+
1 | object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
8+
| ^^^^
9+
| with as a type operator has been deprecated; use & instead
10+
|
11+
| longer explanation available when compiling with `-explain`
712
// defined object IterableTest

compiler/test-resources/type-printer/infix

+21
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,31 @@ def foo: Int && Boolean & String
4848
scala> def foo: Int && (Boolean & String) = ???
4949
def foo: Int && (Boolean & String)
5050
scala> def foo: Int && (Boolean with String) = ???
51+
1 warning found
52+
-- [E003] Syntax Warning: ------------------------------------------------------
53+
1 | def foo: Int && (Boolean with String) = ???
54+
| ^^^^
55+
| with as a type operator has been deprecated; use & instead
56+
|
57+
| longer explanation available when compiling with `-explain`
5158
def foo: Int && (Boolean & String)
5259
scala> def foo: (Int && Boolean) with String = ???
60+
1 warning found
61+
-- [E003] Syntax Warning: ------------------------------------------------------
62+
1 | def foo: (Int && Boolean) with String = ???
63+
| ^^^^
64+
| with as a type operator has been deprecated; use & instead
65+
|
66+
| longer explanation available when compiling with `-explain`
5367
def foo: Int && Boolean & String
5468
scala> def foo: Int && Boolean with String = ???
69+
1 warning found
70+
-- [E003] Syntax Warning: ------------------------------------------------------
71+
1 | def foo: Int && Boolean with String = ???
72+
| ^^^^
73+
| with as a type operator has been deprecated; use & instead
74+
|
75+
| longer explanation available when compiling with `-explain`
5576
def foo: Int && (Boolean & String)
5677
scala> def foo: Int && Boolean | String = ???
5778
def foo: Int && Boolean | String

tests/neg-scalajs/js-native-members.check

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
| The [this] qualifier will be deprecated in the future; it should be dropped.
2929
| See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
3030
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
31+
-- [E003] Syntax Warning: tests/neg-scalajs/js-native-members.scala:58:44 ----------------------------------------------
32+
58 | def assign[T, U](target: T, source: U): T with U = js.native // ok
33+
| ^^^^
34+
| with as a type operator has been deprecated; use & instead
35+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
36+
|
37+
| longer explanation available when compiling with `-explain`
3138
-- Error: tests/neg-scalajs/js-native-members.scala:9:24 ---------------------------------------------------------------
3239
9 | def this(z: String) = this(z.length, z) // error
3340
| ^^^^^^^^^^^^^^^^^

tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:41 -------------------------
2+
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
3+
| ^^^^
4+
| with as a type operator has been deprecated; use & instead
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:35 -------------------------
9+
22 | val g = js.constructorOf[JSClass with JSTrait] // error
10+
| ^^^^
11+
| with as a type operator has been deprecated; use & instead
12+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
13+
|
14+
| longer explanation available when compiling with `-explain`
115
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:13:27 -----------------------------------------
216
13 | val a = js.constructorOf[NativeJSTrait] // error
317
| ^^^^^^^^^^^^^

tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:42 ------------------------
2+
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
3+
| ^^^^
4+
| with as a type operator has been deprecated; use & instead
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E003] Syntax Warning: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:36 ------------------------
9+
22 | val g = js.constructorTag[JSClass with JSTrait] // error
10+
| ^^^^
11+
| with as a type operator has been deprecated; use & instead
12+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
13+
|
14+
| longer explanation available when compiling with `-explain`
115
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:13:42 ----------------------------------------
216
13 | val a = js.constructorTag[NativeJSTrait] // error
317
| ^

tests/neg/i2887b.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait C { type M <: B }
44
trait D { type M >: A }
55

66
object Test {
7-
def test(x: C with D): Unit = {
7+
def test(x: C & D): Unit = {
88
def foo(a: A, b: B)(z: a.S[b.I,a.I][b.S[a.I,a.I]]) = z
99
def bar(a: A, y: x.M) = foo(a,y)
1010
def baz(a: A) = bar(a, a)

tests/neg/i8736.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ object App extends App {
1414
def field[V](s: String)(v: V): Rec[s.type, V] = Rec0(Map(s -> v)).asInstanceOf[Rec[s.type, V]]
1515

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

2020
def rec:
2121
Rec["k", String]
22-
with Rec["v", Int]
23-
with Rec["z", Boolean]
22+
& Rec["v", Int]
23+
& Rec["z", Boolean]
2424
= {
2525
field("k")("Str") +
2626
field("v")(0) +

tests/neg/with-type-operator-future-migration.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
5 |def foo: Int with String = ??? // error
33
| ^^^^
44
| with as a type operator has been deprecated; use & instead
5-
| This construct can be rewritten automatically under -rewrite -source future-migration.
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
66
|
77
| longer explanation available when compiling with `-explain`

tests/pos-deep-subtype/3324h.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//> using options -Xfatal-warnings
22

3+
import scala.language.`3.3`
4+
35
object Test {
46
trait Marker
57
def foo[T](x: T) = x match {
@@ -8,7 +10,7 @@ object Test {
810
}
911

1012
def foo2[T](x: T) = x match {
11-
case _: T with Marker => // scalac emits a warning
13+
case _: T with Marker => // scalac or 3.4 emits a warning
1214
case _ =>
1315
}
1416
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//> using options -Werror
2+
3+
import scala.language.`3.3`
4+
5+
def foo: Int with String = ???
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
//> using options -Werror
1+
import scala.language.`3.4-migration`
22

33
def foo: Int with String = ??? // warn

tests/pos/with-type-operator-future-migration.scala

-3
This file was deleted.

tests/semanticdb/metac.expect

+10-1
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,7 @@ Text => empty
33943394
Language => Scala
33953395
Symbols => 13 entries
33963396
Occurrences => 22 entries
3397+
Diagnostics => 1 entries
33973398

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

3438+
Diagnostics:
3439+
[10:29..10:33): [warning] with as a type operator has been deprecated; use & instead
3440+
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
3441+
34373442
expect/StructuralTypes.scala
34383443
----------------------------
34393444

@@ -5059,7 +5064,7 @@ Text => empty
50595064
Language => Scala
50605065
Symbols => 143 entries
50615066
Occurrences => 246 entries
5062-
Diagnostics => 1 entries
5067+
Diagnostics => 3 entries
50635068
Synthetics => 1 entries
50645069

50655070
Symbols:
@@ -5457,6 +5462,10 @@ Occurrences:
54575462

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

54615470
Synthetics:
54625471
[68:20..68:24):@ann => *[Int]

0 commit comments

Comments
 (0)