Skip to content

Commit 7f26941

Browse files
committed
Deprecation warnings for old syntax: _ type wildcards
* In `3.4` we emit the deprecation warning and enable the patch with `-rewrite`. * In `future` we emit we make this syntax an error
1 parent f61026d commit 7f26941

9 files changed

+39
-9
lines changed

Diff for: compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -1861,8 +1861,10 @@ object Parsers {
18611861
val start = in.skipToken()
18621862
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18631863
else
1864-
if sourceVersion.isAtLeast(future) then
1865-
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
1864+
report.errorOrMigrationWarning(
1865+
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`future-migration`)}",
1866+
in.sourcePos(), from = future)
1867+
if sourceVersion == `future-migration` then
18661868
patch(source, Span(in.offset, in.offset + 1), "?")
18671869
val start = in.skipToken()
18681870
typeBounds().withSpan(Span(start, in.lastOffset, start))

Diff for: compiler/test-resources/repl/i13208.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//> using options -source:future -deprecation
1+
//> using options -source:future-migration
22
scala> type M[X] = X match { case Int => String case _ => Int }
33
scala> type N[X] = X match { case List[_] => Int }
44
1 warning found
5-
-- Deprecation Warning: --------------------------------------------------------
5+
-- Migration Warning: ----------------------------------------------------------
66
1 | type N[X] = X match { case List[_] => Int }
77
| ^
8-
| `_` is deprecated for wildcard arguments of types: use `?` instead
8+
| `_` is deprecated for wildcard arguments of types: use `?` instead

Diff for: sbt-test/compilerReporter/i14576/Test.scala

-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ object Test:
1212

1313
// private[this] and = _ are deprecated under -source:future
1414
private[this] var x: AnyRef = _
15-
16-
// under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead
17-
val xs: List[_] = Nil

Diff for: sbt-test/compilerReporter/i14576/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lazy val root = (project in file("."))
2424
},
2525
assertDeprecationSummary := {
2626
assert {
27-
FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warnings; re-run with -deprecation for details"))
27+
FakePrintWriter.messages.exists(_.contains("there were 2 deprecation warnings; re-run with -deprecation for details"))
2828
}
2929
},
3030
assertNoDeprecationSummary := {
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg/wildcard-type-syntax-future-migration.scala:7:17 ---------------------------------------------------
2+
7 | case _: List[_] => // error
3+
| ^
4+
| `_` is deprecated for wildcard arguments of types: use `?` instead
5+
| This construct can be rewritten automatically under -rewrite -source future-migration.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Werror
2+
3+
import scala.language.`future-migration`
4+
5+
def test =
6+
Seq() match
7+
case _: List[_] => // error
8+
case _: Seq[?] =>

Diff for: tests/neg/wildcard-type-syntax-future.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.future
2+
3+
def test =
4+
Seq() match
5+
case _: List[_] => // error
6+
case _: Seq[?] =>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.language.`future-migration`
2+
3+
def test =
4+
Seq() match
5+
case _: List[_] => // warn
6+
case _: Seq[?] =>

Diff for: tests/pos/wildcard-type-syntax.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Werror
2+
3+
def test =
4+
Seq() match
5+
case _: List[_] => // error
6+
case _: Seq[?] =>

0 commit comments

Comments
 (0)