diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 327f97a3cc9d..5642443eae73 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -413,6 +413,14 @@ object Parsers { finally inEnum = saved } + private var inTypeMatchPattern = false + private def withinTypeMatchPattern[T](body: => T): T = { + val saved = inTypeMatchPattern + inTypeMatchPattern = true + try body + finally inTypeMatchPattern = saved + } + private var staged = StageKind.None def withinStaged[T](kind: StageKind)(op: => T): T = { val saved = staged @@ -1862,7 +1870,7 @@ object Parsers { val start = in.skipToken() Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start)) else - if sourceVersion.isAtLeast(future) then + if !inTypeMatchPattern && sourceVersion.isAtLeast(future) then deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead") patch(source, Span(in.offset, in.offset + 1), "?") val start = in.skipToken() @@ -2898,7 +2906,7 @@ object Parsers { val start = in.skipToken() Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start)) case _ => - rejectWildcardType(infixType()) + withinTypeMatchPattern(rejectWildcardType(infixType())) } } CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) { diff --git a/compiler/test-resources/repl/i13208.scala b/compiler/test-resources/repl/i13208.scala index 61ace43c732d..07cc67d3bf0b 100644 --- a/compiler/test-resources/repl/i13208.scala +++ b/compiler/test-resources/repl/i13208.scala @@ -1,8 +1,3 @@ //> using options -source:future -deprecation scala> type M[X] = X match { case Int => String case _ => Int } scala> type N[X] = X match { case List[_] => Int } -1 warning found --- Deprecation Warning: -------------------------------------------------------- -1 | type N[X] = X match { case List[_] => Int } - | ^ - | `_` is deprecated for wildcard arguments of types: use `?` instead diff --git a/tests/pos/i18808.scala b/tests/pos/i18808.scala new file mode 100644 index 000000000000..0556b3285d00 --- /dev/null +++ b/tests/pos/i18808.scala @@ -0,0 +1,9 @@ +//> using options -Werror + +import language.future + +type F[X] = X match + case List[_] => Int + +type G[X] = X match + case List[?] => Int