diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 725c47a5097c..fc61be0b0e83 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -430,12 +430,12 @@ object Parsers { finally inEnum = saved } - private var inTypeMatchPattern = false - private def withinTypeMatchPattern[T](body: => T): T = { - val saved = inTypeMatchPattern - inTypeMatchPattern = true + private var inMatchPattern = false + private def withinMatchPattern[T](body: => T): T = { + val saved = inMatchPattern + inMatchPattern = true try body - finally inTypeMatchPattern = saved + finally inMatchPattern = saved } private var staged = StageKind.None @@ -1881,7 +1881,7 @@ object Parsers { val start = in.skipToken() Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start)) else - if !inTypeMatchPattern then + if !inMatchPattern then report.errorOrMigrationWarning( em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}", in.sourcePos(), @@ -2896,7 +2896,7 @@ object Parsers { def caseClause(exprOnly: Boolean = false): CaseDef = atSpan(in.offset) { val (pat, grd) = inSepRegion(InCase) { accept(CASE) - (pattern(), guard()) + (withinMatchPattern(pattern()), guard()) } CaseDef(pat, grd, atSpan(accept(ARROW)) { if exprOnly then @@ -2920,7 +2920,7 @@ object Parsers { val start = in.skipToken() Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start)) case _ => - withinTypeMatchPattern(rejectWildcardType(infixType())) + withinMatchPattern(rejectWildcardType(infixType())) } } CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) { diff --git a/tests/neg/wildcard-type-syntax-3.4.check b/tests/neg/wildcard-type-syntax-3.4.check deleted file mode 100644 index 9b2d755b64eb..000000000000 --- a/tests/neg/wildcard-type-syntax-3.4.check +++ /dev/null @@ -1,5 +0,0 @@ --- Error: tests/neg/wildcard-type-syntax-3.4.scala:7:17 ---------------------------------------------------------------- -7 | case _: List[_] => // error: migration warning - | ^ - | `_` is deprecated for wildcard arguments of types: use `?` instead - | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/wildcard-type-syntax-3.4.scala b/tests/neg/wildcard-type-syntax-3.4.scala deleted file mode 100644 index 1123c9cbbe35..000000000000 --- a/tests/neg/wildcard-type-syntax-3.4.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -Werror - -import scala.language.`3.4-migration` - -def test = - Seq() match - case _: List[_] => // error: migration warning - case _: Seq[?] => diff --git a/tests/neg/wildcard-type-syntax-future-migration.scala b/tests/neg/wildcard-type-syntax-future-migration.scala deleted file mode 100644 index 6a5367385ab0..000000000000 --- a/tests/neg/wildcard-type-syntax-future-migration.scala +++ /dev/null @@ -1,8 +0,0 @@ -//> using options -Werror - -import scala.language.`future-migration` - -def test = - Seq() match - case _: List[_] => // error: migration warning - case _: Seq[?] => diff --git a/tests/neg/wildcard-type-syntax-future.scala b/tests/neg/wildcard-type-syntax-future.scala deleted file mode 100644 index 750fd55ec226..000000000000 --- a/tests/neg/wildcard-type-syntax-future.scala +++ /dev/null @@ -1,6 +0,0 @@ -import scala.language.future - -def test = - Seq() match - case _: List[_] => // error - case _: Seq[?] => diff --git a/tests/pos/wildcard-type-syntax.scala b/tests/pos/wildcard-type-syntax.scala index 26bbaa319277..5e354b7b21ac 100644 --- a/tests/pos/wildcard-type-syntax.scala +++ b/tests/pos/wildcard-type-syntax.scala @@ -1,7 +1,5 @@ //> using options -Werror -import scala.language.`3.3` - def test = Seq() match case _: List[_] => diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 2fd8eca47a7b..517924bf5e4f 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -62,7 +62,7 @@ Text => empty Language => Scala Symbols => 61 entries Occurrences => 143 entries -Diagnostics => 4 entries +Diagnostics => 3 entries Synthetics => 3 entries Symbols: @@ -278,8 +278,6 @@ Diagnostics: This construct can be rewritten automatically under -rewrite -source 3.4-migration. [21:15..21:15): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[39:20..39:20): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead -This construct can be rewritten automatically under -rewrite -source 3.4-migration. [40:12..40:15): [warning] unused local definition Synthetics: @@ -395,7 +393,7 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 50 entries -Diagnostics => 4 entries +Diagnostics => 3 entries Synthetics => 2 entries Symbols: @@ -480,8 +478,6 @@ Diagnostics: This construct can be rewritten automatically under -rewrite -source 3.4-migration. [9:22..9:22): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[11:29..11:29): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead -This construct can be rewritten automatically under -rewrite -source 3.4-migration. [14:8..14:9): [warning] unused local definition Synthetics: