File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -3177,7 +3177,11 @@ 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 isVariable = unsplice(p) match {
3181+ case x : Ident => x.name.isVarPattern
3182+ case _ => false
3183+ }
3184+ val isVariableOrNumber = isVariable || p.isInstanceOf [Number ]
31813185 if ! isVariableOrNumber then
31823186 report.errorOrMigrationWarning(
31833187 em """ Type ascriptions after patterns other than:
Original file line number Diff line number Diff line change 1010 | Not found: A
1111 |
1212 | longer explanation available when compiling with `-explain`
13+ -- Warning: tests/neg/i15784.scala:7:8 ---------------------------------------------------------------------------------
14+ 7 | case X: Int => X // warn
15+ | ^
16+ | Type ascriptions after patterns other than:
17+ | * variable pattern, e.g. `case x: String =>`
18+ | * number literal pattern, e.g. `case 10.5: Double =>`
19+ | are no longer supported. Remove the type ascription or move it to a separate variable pattern.
20+ -- Warning: tests/neg/i15784.scala:10:12 -------------------------------------------------------------------------------
21+ 10 | case `Int`: Int => `Int` // warn
22+ | ^
23+ | Type ascriptions after patterns other than:
24+ | * variable pattern, e.g. `case x: String =>`
25+ | * number literal pattern, e.g. `case 10.5: Double =>`
26+ | are no longer supported. Remove the type ascription or move it to a separate variable pattern.
Original file line number Diff line number Diff line change 11def i15784 = List (42 ) match
22 case List (_, Rest @ `a`) => Rest // error
33 case List (_, Rest @ A ) => Rest // error
4- case _ => ???
4+ case _ => ???
5+
6+ def case2 = 42 match
7+ case X : Int => X // warn
8+
9+ def case3 = 42 match
10+ case `Int` : Int => `Int` // warn
Original file line number Diff line number Diff line change 1- def i15784 = List (42 ) match
1+ //> using options -Werror
2+
3+ def case1 = List (42 ) match
24 case List (_, rest @ _* ) => rest
5+ case _ => ???
6+
7+ def case2 = List (42 ) match
38 case List (_, Rest @ _* ) => Rest
9+ case _ => ???
10+
11+ def case3 = List (42 ) match
412 case List (_, `Rest` @ _* ) => Rest
513 case _ => ???
614
7- def i15784_auxiliary = 42 match
15+ def case4 = 42 match
816 case `type` : Int => `type`
17+
18+ def case5 = 42 match
19+ case X @ (_ : Int ) => 32
You can’t perform that action at this time.
0 commit comments