diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-03-26 19:35:23 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-05-01 13:27:42 +0200 |
commit | 8bd4139db4dd89e83b71a49b39c0747b9f5fc68a (patch) | |
tree | 7b7b595e6ded5a2960b939354b33b52e87693c5d /tests | |
parent | 9c94605d5464936cc156680c5db5344d5ff092ef (diff) | |
download | dotty-8bd4139db4dd89e83b71a49b39c0747b9f5fc68a.tar.gz dotty-8bd4139db4dd89e83b71a49b39c0747b9f5fc68a.tar.bz2 dotty-8bd4139db4dd89e83b71a49b39c0747b9f5fc68a.zip |
Erasure: properly handle null in value classes
This fixes the issues reported in SI-5866 and SI-8097
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pos/valueclasses/nullAsInstanceOfVC.scala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/pos/valueclasses/nullAsInstanceOfVC.scala b/tests/pos/valueclasses/nullAsInstanceOfVC.scala new file mode 100644 index 000000000..0c1232883 --- /dev/null +++ b/tests/pos/valueclasses/nullAsInstanceOfVC.scala @@ -0,0 +1,27 @@ +// These issues were originally reported in SI-5866 and SI-8097 +// FIXME: Make this a run test once we have run tests. + +object VCNull { + case class Foo(d: Double) extends AnyVal { + override def toString = s"Foo($d)" + } + case class Bar(s: String) extends AnyVal { + override def toString = s"Bar($s)" + } + + def testDirect(): Unit = { + val fooDirect: Foo = null.asInstanceOf[Foo] + val barDirect: Bar = null.asInstanceOf[Bar] + } + + def testIndirect(): Unit = { + val fooIndirect: Foo = { val n: Any = null; n.asInstanceOf[Foo] } + val barIndirect: Bar = { val n: Any = null; n.asInstanceOf[Bar] } + } + + def nullOf[T]: T = null.asInstanceOf[T] + def testGeneric(): Unit = { + val fooGeneric: Foo = nullOf[Foo] + val barGeneric: Bar = nullOf[Bar] + } +} |