blob: 43af839ec6b035dc865321f71b04959a52c2c67b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package nullAsInstanceOfVC
// 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]
}
}
|