File tree 4 files changed +39
-4
lines changed
compiler/src/dotty/tools/dotc/parsing
4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -2960,7 +2960,11 @@ object Parsers {
2960
2960
def pattern1 (location : Location = Location .InPattern ): Tree =
2961
2961
val p = pattern2()
2962
2962
if in.isColon then
2963
- val isVariableOrNumber = isVarPattern(p) || p.isInstanceOf [Number ]
2963
+ val isVariable = unsplice(p) match {
2964
+ case x : Ident => x.name.isVarPattern
2965
+ case _ => false
2966
+ }
2967
+ val isVariableOrNumber = isVariable || p.isInstanceOf [Number ]
2964
2968
if ! isVariableOrNumber then
2965
2969
report.gradualErrorOrMigrationWarning(
2966
2970
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 case2 = List (42 ) match
3
8
case List (_, Rest @ _* ) => Rest
9
+ case _ => ???
10
+
11
+ def case3 = List (42 ) match
4
12
case List (_, `Rest` @ _* ) => Rest
5
13
case _ => ???
6
14
7
- def i15784_auxiliary = 42 match
15
+ def case4 = 42 match
8
16
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