Skip to content

Commit 9a5a517

Browse files
committed
Fix #1490: type test of union types via type alias
1 parent 5032f71 commit 9a5a517

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ trait TypeTestsCasts {
100100
* The transform happens before erasure of `argType`, thus cannot be merged
101101
* with `transformIsInstanceOf`, which depends on erased type of `argType`.
102102
*/
103-
def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType match {
103+
def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match {
104104
case OrType(tp1, tp2) =>
105105
evalOnce(qual) { fun =>
106106
transformOrTypeTest(fun, tp1)

tests/run/i1490.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
true
2+
true
3+
false

tests/run/i1490.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Base {
2+
type T = Int | Boolean
3+
def test(x: Object) = x.isInstanceOf[T]
4+
}
5+
6+
object Test {
7+
def main(args: Array[String]) = {
8+
val b = new Base
9+
println(b.test(Int.box(3)))
10+
println(b.test(Boolean.box(false)))
11+
println(b.test(Double.box(3.4)))
12+
}
13+
}

0 commit comments

Comments
 (0)