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 9, 2023
1 parent c7b3d7b commit 4991296
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 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
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 4991296

Please sign in to comment.