Skip to content

Commit bde30c9

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

7 files changed

+10
-43
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[_] =>

tests/semanticdb/metac.expect

+2-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Text => empty
6262
Language => Scala
6363
Symbols => 61 entries
6464
Occurrences => 143 entries
65-
Diagnostics => 4 entries
65+
Diagnostics => 3 entries
6666
Synthetics => 3 entries
6767

6868
Symbols:
@@ -278,8 +278,6 @@ Diagnostics:
278278
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
279279
[21:15..21:15): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
280280
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
281-
[39:20..39:20): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
282-
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
283281
[40:12..40:15): [warning] unused local definition
284282

285283
Synthetics:
@@ -395,7 +393,7 @@ Text => empty
395393
Language => Scala
396394
Symbols => 23 entries
397395
Occurrences => 50 entries
398-
Diagnostics => 4 entries
396+
Diagnostics => 3 entries
399397
Synthetics => 2 entries
400398

401399
Symbols:
@@ -480,8 +478,6 @@ Diagnostics:
480478
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
481479
[9:22..9:22): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
482480
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
483-
[11:29..11:29): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
484-
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
485481
[14:8..14:9): [warning] unused local definition
486482

487483
Synthetics:

0 commit comments

Comments
 (0)