Skip to content

Commit

Permalink
Disallow _ for wildcard arguments of types and use ? in future
Browse files Browse the repository at this point in the history
* In `future-migration` we emit the deprecation warning and enable the
  patch with `-rewrite`.
* In `future` we emit we make this syntax an error
  • Loading branch information
nicolasstucki committed Nov 1, 2023
1 parent 1e95432 commit 50e94f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,10 @@ object Parsers {
val start = in.skipToken()
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
else
if sourceVersion.isAtLeast(future) then
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
report.errorOrMigrationWarning(
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`future-migration`)}",
in.sourcePos(), from = future)
if sourceVersion == `future-migration` then
patch(source, Span(in.offset, in.offset + 1), "?")
val start = in.skipToken()
typeBounds().withSpan(Span(start, in.lastOffset, start))
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/wildcard-type-syntax-future-migration.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Error: tests/neg/wildcard-type-syntax-future-migration.scala:7:17 ---------------------------------------------------
7 | case _: List[_] => // error
| ^
| `_` is deprecated for wildcard arguments of types: use `?` instead
| This construct can be rewritten automatically under -rewrite -source future-migration.
8 changes: 8 additions & 0 deletions tests/neg/wildcard-type-syntax-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//> using options -Werror

import scala.language.`future-migration`

def test =
Seq() match
case _: List[_] => // error
case _: Seq[?] =>
6 changes: 6 additions & 0 deletions tests/neg/wildcard-type-syntax-future.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.future

def test =
Seq() match
case _: List[_] => // error
case _: Seq[?] =>
6 changes: 6 additions & 0 deletions tests/pos/wildcard-type-syntax-future-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.`future-migration`

def test =
Seq() match
case _: List[_] => // warn
case _: Seq[?] =>

0 comments on commit 50e94f6

Please sign in to comment.