Skip to content

Commit b7d3167

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 b7d3167

10 files changed

+51
-9
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1861,8 +1861,12 @@ 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.gradualErrorOrMigrationWarning(
1865+
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
1866+
in.sourcePos(),
1867+
warnFrom = `3.4`,
1868+
errorFrom = future)
1869+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
18661870
patch(source, Span(in.offset, in.offset + 1), "?")
18671871
val start = in.skipToken()
18681872
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:3.4-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 := {

Diff for: tests/neg/wildcard-type-syntax-3.4.check

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg/wildcard-type-syntax-3.4.scala:7:17 ----------------------------------------------------------------
2+
7 | case _: List[_] => // error: migration warning
3+
| ^
4+
| `_` is deprecated for wildcard arguments of types: use `?` instead
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.

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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Werror
2+
3+
import scala.language.`3.4-migration`
4+
5+
def test =
6+
Seq() match
7+
case _: List[_] => // error: migration warning
8+
case _: Seq[?] =>
+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: migration warning
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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options -Werror
2+
3+
import scala.language.`3.3`
4+
5+
def test =
6+
Seq() match
7+
case _: List[_] =>
8+
case _: Seq[?] =>

0 commit comments

Comments
 (0)