Skip to content

Commit db40ef5

Browse files
committed
Fix #3812: Refine tests for pattern match
1 parent d340a4d commit db40ef5

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

tests/neg/i1846.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
object Test {
22
def main(args: Array[String]): Unit = {
33
val x = 42
4-
val Y = "h"
4+
val Y = "42"
55

6-
x match { case { 42 } => 42 } // ok
7-
x match { case { 42.toString } => 42 } // error
8-
x match { case { 42 }.toString => 42 } // error
9-
x match { case { "h" }.toString => println(42) } // error
10-
x match { case { "h".toString } => println(42) } // error
11-
x match { case Y => println(42) } // error
12-
x match { case Y.toString => println(42) } // error
13-
14-
Y match { case Y.toString => println(42) } // ok
15-
Y match { case { Y.toString } => println(42) } // ok
16-
Y match { case { Y }.toString => println(42) } // ok
6+
x match { case { 42 } => () } // ok
7+
x match { case { 42.toString } => () } // error
8+
x match { case { 42 }.toString => () } // error
9+
x match { case "42".toInt => () } // error
10+
x match { case { "42".toInt } => () } // ok
11+
x match { case { "42" }.toInt => () } // ok
12+
x match { case { "42".toInt } => () } // ok
13+
x match { case Y => () } // error
14+
x match { case Y.toInt => () } // ok
15+
x match { case { Y.toInt } => () } // ok
16+
x match { case { Y }.toInt => () } // ok
17+
x match { case Y.toString => () } // error
18+
x match { case { Y }.toString => () } // error
19+
x match { case { Y.toString } => () } // error
1720
}
1821
}

tests/run/i3812.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val x = 42
4+
val Y = "42"
5+
6+
x match { case { 42 } => () } // ok
7+
x match { case { "42".toInt } => () } // ok
8+
x match { case { "42" }.toInt => () } // ok
9+
x match { case { "42".toInt } => () } // ok
10+
x match { case { Y.toInt } => () } // ok
11+
x match { case { Y }.toInt => () } // ok
12+
13+
// x match { case Y.toInt => () } // compiles but rejected by Ycheck
14+
}
15+
}

0 commit comments

Comments
 (0)