File tree 5 files changed +42
-7
lines changed
compiler/src/dotty/tools/dotc/parsing
5 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -3177,7 +3177,11 @@ object Parsers {
3177
3177
def pattern1 (location : Location = Location .InPattern ): Tree =
3178
3178
val p = pattern2(location)
3179
3179
if in.isColon then
3180
- val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf [Number ] || isBackquoted(p)
3180
+ val isVariable = unsplice(p) match {
3181
+ case x : Ident => x.name.isVarPattern
3182
+ case _ => false
3183
+ }
3184
+ val isVariableOrNumber = isVariable || p.isInstanceOf [Number ]
3181
3185
if ! isVariableOrNumber then
3182
3186
report.errorOrMigrationWarning(
3183
3187
em """ Type ascriptions after patterns other than:
Original file line number Diff line number Diff line change 10
10
| Not found: A
11
11
|
12
12
| 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 1
1
def i15784 = List (42 ) match
2
2
case List (_, Rest @ `a`) => Rest // error
3
3
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
2
4
case List (_, rest @ _* ) => rest
5
+ case _ => ???
6
+
7
+ def case3 = List (42 ) match
3
8
case List (_, Rest @ _* ) => Rest
9
+ case _ => ???
10
+
11
+ def case2 = List (42 ) match
4
12
case List (_, `Rest` @ _* ) => Rest
5
- case _ => ???
13
+ case _ => ???
14
+
15
+ def case4 = 42 match
16
+ case `type` : Int => `type`
17
+
18
+ def case5 = 42 match
19
+ case X @ (_ : Int ) => 32
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments