diff options
author | liu fengyun <liufengyunchina@gmail.com> | 2016-07-26 10:20:34 +0200 |
---|---|---|
committer | liu fengyun <liufengyunchina@gmail.com> | 2016-07-26 14:37:31 +0200 |
commit | 25421111a730681504c73b978e454dfa7a6ff447 (patch) | |
tree | e722a7cdc524c0eeacf76b4d6f627406ef4d5c0c /tests/run | |
parent | b6882d6402bfc290a1fe589425d6dc4ff16976a8 (diff) | |
download | dotty-25421111a730681504c73b978e454dfa7a6ff447.tar.gz dotty-25421111a730681504c73b978e454dfa7a6ff447.tar.bz2 dotty-25421111a730681504c73b978e454dfa7a6ff447.zip |
fix #1354: improve type test and typecast of union types
Diffstat (limited to 'tests/run')
-rw-r--r-- | tests/run/i1354.check | 6 | ||||
-rw-r--r-- | tests/run/i1354.scala | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/run/i1354.check b/tests/run/i1354.check new file mode 100644 index 000000000..ce686866d --- /dev/null +++ b/tests/run/i1354.check @@ -0,0 +1,6 @@ +0 +false +5 +1 +true +true 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]) + } +} |