Fix unboxing values of inline class type from type parameters
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Result<T>(val a: Any?) {
|
||||
fun typed(): T = a as T
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val asInt = Result<Int>(19)
|
||||
val asString = Result<String>("sample")
|
||||
val asResult = Result<Result<Int>>(asInt)
|
||||
|
||||
val unboxedInt = asInt.typed()
|
||||
val unboxedString = asString.typed()
|
||||
val unboxedResult = asResult.typed()
|
||||
|
||||
if (unboxedInt != 19) return "fail"
|
||||
if (unboxedString != "sample") return "fail"
|
||||
if (unboxedResult.typed() != 19) return "fail"
|
||||
|
||||
if (asResult.typed().typed() != 19) return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Result<T>(val a: Any?) {
|
||||
fun typed(): T = a as T
|
||||
}
|
||||
|
||||
fun <K> materialize(): K = TODO()
|
||||
|
||||
fun test(asInt: Result<Int>, asString: Result<String>, asResult: Result<Result<Int>>) {
|
||||
val a1 = materialize<Result<Int>>() // unbox
|
||||
val a2 = materialize<Result<Result<Int>>>() // unbox
|
||||
|
||||
val b1 = asInt.typed() // intValue
|
||||
val b2 = asString.typed()
|
||||
|
||||
val c1 = asResult.typed() // unbox
|
||||
|
||||
materialize<Result<Int>>()
|
||||
asInt.typed()
|
||||
asString.typed()
|
||||
asResult.typed()
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC Result\$Erased.box
|
||||
// 3 INVOKEVIRTUAL Result.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 1 intValue
|
||||
Reference in New Issue
Block a user