From 25421111a730681504c73b978e454dfa7a6ff447 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 26 Jul 2016 10:20:34 +0200 Subject: fix #1354: improve type test and typecast of union types --- tests/run/i1354.scala | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/run/i1354.scala (limited to 'tests/run/i1354.scala') diff --git a/tests/run/i1354.scala b/tests/run/i1354.scala new file mode 100644 index 000000000..08b129e4e --- /dev/null +++ b/tests/run/i1354.scala @@ -0,0 +1,27 @@ +object Test { + def foo(a: Int | Double) = a match { + case a: (Float | Boolean) => 1 + case _ => 0 + } + + def typeTest(a: Int | Double) = a.isInstanceOf[Float | Boolean] // false + + def typeCast(a: Int | Double) = a.asInstanceOf[Float | Boolean] // no error + + def main(args: Array[String]): Unit = { + println(foo(4)) + + println(typeTest(4)) + + println(typeCast(5)) + + Boolean.box(true) match { + case a: (Float | Boolean) => println(1) + case _ => println(0) + } + + println(Boolean.box(true).isInstanceOf[Float | Boolean]) + + println(Boolean.box(true).asInstanceOf[Float | Boolean]) + } +} -- cgit v1.2.3