Skip to content

Commit

Permalink
Do not show deprecation waning for _ in type match case
Browse files Browse the repository at this point in the history
Fixes #18808
  • Loading branch information
nicolasstucki committed Nov 10, 2023
1 parent c7b3d7b commit 6d7aa99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 0 additions & 5 deletions compiler/test-resources/repl/i13208.scala
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/pos/i18808.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6d7aa99

Please sign in to comment.