Skip to content

Commit 11daf96

Browse files
committed
Do not warn on underscore wildcard type in pattern
Part of #18869
1 parent feed938 commit 11daf96

6 files changed

+8
-37
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ object Parsers {
430430
finally inEnum = saved
431431
}
432432

433-
private var inTypeMatchPattern = false
434-
private def withinTypeMatchPattern[T](body: => T): T = {
435-
val saved = inTypeMatchPattern
436-
inTypeMatchPattern = true
433+
private var inMatchPattern = false
434+
private def withinMatchPattern[T](body: => T): T = {
435+
val saved = inMatchPattern
436+
inMatchPattern = true
437437
try body
438-
finally inTypeMatchPattern = saved
438+
finally inMatchPattern = saved
439439
}
440440

441441
private var staged = StageKind.None
@@ -1881,7 +1881,7 @@ object Parsers {
18811881
val start = in.skipToken()
18821882
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18831883
else
1884-
if !inTypeMatchPattern then
1884+
if !inMatchPattern then
18851885
report.errorOrMigrationWarning(
18861886
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
18871887
in.sourcePos(),
@@ -2896,7 +2896,7 @@ object Parsers {
28962896
def caseClause(exprOnly: Boolean = false): CaseDef = atSpan(in.offset) {
28972897
val (pat, grd) = inSepRegion(InCase) {
28982898
accept(CASE)
2899-
(pattern(), guard())
2899+
(withinMatchPattern(pattern()), guard())
29002900
}
29012901
CaseDef(pat, grd, atSpan(accept(ARROW)) {
29022902
if exprOnly then
@@ -2920,7 +2920,7 @@ object Parsers {
29202920
val start = in.skipToken()
29212921
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
29222922
case _ =>
2923-
withinTypeMatchPattern(rejectWildcardType(infixType()))
2923+
withinMatchPattern(rejectWildcardType(infixType()))
29242924
}
29252925
}
29262926
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {

tests/neg/wildcard-type-syntax-3.4.check

-5
This file was deleted.

tests/neg/wildcard-type-syntax-3.4.scala

-8
This file was deleted.

tests/neg/wildcard-type-syntax-future-migration.scala

-8
This file was deleted.

tests/neg/wildcard-type-syntax-future.scala

-6
This file was deleted.

tests/pos/wildcard-type-syntax.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//> using options -Werror
22

3-
import scala.language.`3.3`
4-
53
def test =
64
Seq() match
75
case _: List[_] =>

0 commit comments

Comments
 (0)