Skip to content

Commit 4991296

Browse files
committed
Do not show deprecation waning for _ in type match case
Fixes #18808
1 parent c7b3d7b commit 4991296

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+10-2
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ object Parsers {
413413
finally inEnum = saved
414414
}
415415

416+
private var inTypeMatchPattern = false
417+
private def withinTypeMatchPattern[T](body: => T): T = {
418+
val saved = inTypeMatchPattern
419+
inTypeMatchPattern = true
420+
try body
421+
finally inTypeMatchPattern = saved
422+
}
423+
416424
private var staged = StageKind.None
417425
def withinStaged[T](kind: StageKind)(op: => T): T = {
418426
val saved = staged
@@ -1862,7 +1870,7 @@ object Parsers {
18621870
val start = in.skipToken()
18631871
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18641872
else
1865-
if sourceVersion.isAtLeast(future) then
1873+
if !inTypeMatchPattern && sourceVersion.isAtLeast(future) then
18661874
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
18671875
patch(source, Span(in.offset, in.offset + 1), "?")
18681876
val start = in.skipToken()
@@ -2898,7 +2906,7 @@ object Parsers {
28982906
val start = in.skipToken()
28992907
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
29002908
case _ =>
2901-
rejectWildcardType(infixType())
2909+
withinTypeMatchPattern(rejectWildcardType(infixType()))
29022910
}
29032911
}
29042912
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {

tests/pos/i18808.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Werror
2+
3+
import language.future
4+
5+
type F[X] = X match
6+
case List[_] => Int
7+
8+
type G[X] = X match
9+
case List[?] => Int

0 commit comments

Comments
 (0)