Skip to content

Commit 894b6c5

Browse files
committed
Fix incorrect warning on type ascription for backquoted identifiers in patterns
1 parent 77401fa commit 894b6c5

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3177,7 +3177,7 @@ object Parsers {
31773177
def pattern1(location: Location = Location.InPattern): Tree =
31783178
val p = pattern2(location)
31793179
if in.isColon then
3180-
val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf[Number]
3180+
val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf[Number] || isBackquoted(p)
31813181
if !isVariableOrNumber then
31823182
report.errorOrMigrationWarning(
31833183
em"""Type ascriptions after patterns other than:

tests/pos/i15784.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ def i15784 = List(42) match
22
case List(_, rest @ _*) => rest
33
case List(_, Rest @ _*) => Rest
44
case List(_, `Rest` @ _*) => Rest
5-
case _ => ???
6-
7-
def i15784_auxiliary = 42 match
8-
case `type` : Int => `type`
5+
case _ => ???

tests/pos/i22989.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//> using options -Xfatal-warnings
2+
def foo = 42 match
3+
case `type` : Int => `type`

0 commit comments

Comments
 (0)