File tree 1 file changed +26
-0
lines changed 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ object Test {
2
+ case object Bob { override def equals (other : Any ) = true }
3
+
4
+ class Bob2 {
5
+ override def equals (other : Any ) = true
6
+ }
7
+ val Bob2 = new Bob2
8
+
9
+ def f0 (x : Any ) = x match { case Bob2 => Bob2 } // class cast exception at runtime, dotc only
10
+ def f1 (x : Any ) = x match { case Bob => Bob } // class cast exception at runtime, dotc only
11
+ def f2 (x : Any ): Bob .type = x match { case x @ Bob => x } // class cast exception at runtime, dotc and javac.
12
+
13
+ def main (args : Array [String ]): Unit = {
14
+ assert(f0(Bob2 ) eq Bob2 )
15
+ assert(f0(0 ) eq Bob2 ) // only dotty fails here
16
+ assert(f0(Nil ) eq Bob2 )
17
+
18
+ assert(f1(Bob ) eq Bob )
19
+ assert(f1(0 ) eq Bob ) // only dotty fails here
20
+ assert(f1(Nil ) eq Bob )
21
+
22
+ assert(f2(Bob ) eq Bob )
23
+ // assert(f2(0) eq Bob) // both dotty and scalac fail here
24
+ // assert(f2(Nil) eq Bob)
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments