From 9a5a51768d0f5bc0db9d91418be16a4e3b0e6937 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Thu, 1 Sep 2016 14:55:01 +0200 Subject: [PATCH] Fix #1490: type test of union types via type alias --- src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 2 +- tests/run/i1490.check | 3 +++ tests/run/i1490.scala | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/run/i1490.check create mode 100644 tests/run/i1490.scala diff --git a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 6de2bf44c3e8..3774127fad8f 100644 --- a/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -100,7 +100,7 @@ trait TypeTestsCasts { * The transform happens before erasure of `argType`, thus cannot be merged * with `transformIsInstanceOf`, which depends on erased type of `argType`. */ - def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType match { + def transformOrTypeTest(qual: Tree, argType: Type): Tree = argType.dealias match { case OrType(tp1, tp2) => evalOnce(qual) { fun => transformOrTypeTest(fun, tp1) diff --git a/tests/run/i1490.check b/tests/run/i1490.check new file mode 100644 index 000000000000..9e8a46acf90a --- /dev/null +++ b/tests/run/i1490.check @@ -0,0 +1,3 @@ +true +true +false diff --git a/tests/run/i1490.scala b/tests/run/i1490.scala new file mode 100644 index 000000000000..554bc3940c17 --- /dev/null +++ b/tests/run/i1490.scala @@ -0,0 +1,13 @@ +class Base { + type T = Int | Boolean + def test(x: Object) = x.isInstanceOf[T] +} + +object Test { + def main(args: Array[String]) = { + val b = new Base + println(b.test(Int.box(3))) + println(b.test(Boolean.box(false))) + println(b.test(Double.box(3.4))) + } +} \ No newline at end of file