diff options
author | odersky <odersky@gmail.com> | 2016-07-27 15:45:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-27 15:45:21 +0200 |
commit | 5ffce6e910f4cc1fced15824df86a9524be81681 (patch) | |
tree | 09b9ed81fe4457338db10982a47a62936fb2eca7 /tests | |
parent | fec3ec3e1f5b8c1ed9af3c51010832f99d958b23 (diff) | |
parent | 25421111a730681504c73b978e454dfa7a6ff447 (diff) | |
download | dotty-5ffce6e910f4cc1fced15824df86a9524be81681.tar.gz dotty-5ffce6e910f4cc1fced15824df86a9524be81681.tar.bz2 dotty-5ffce6e910f4cc1fced15824df86a9524be81681.zip |
Merge pull request #1415 from dotty-staging/fix-i1354
fix #1354: improve type test of union types
Diffstat (limited to 'tests')
-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]) + } +} |