Skip to content

Commit 6ca9de0

Browse files
committed
Disallow _ for wildcard arguments of types and use ? in future
* In `future-migration` we emit the deprecation warning and enable the patch with `-rewrite`. * In `future` we emit we make this syntax an error
1 parent 1e95432 commit 6ca9de0

8 files changed

+36
-6
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1856,8 +1856,10 @@ object Parsers {
18561856
val start = in.skipToken()
18571857
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18581858
else
1859-
if sourceVersion.isAtLeast(future) then
1860-
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
1859+
report.errorOrMigrationWarning(
1860+
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`future-migration`)}",
1861+
in.sourcePos(), from = future)
1862+
if sourceVersion == `future-migration` then
18611863
patch(source, Span(in.offset, in.offset + 1), "?")
18621864
val start = in.skipToken()
18631865
typeBounds().withSpan(Span(start, in.lastOffset, start))

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)