Fix mapping of nullable generic underlying types of inline classes

#KT-32162 Fixed
This commit is contained in:
Ilmir Usmanov
2022-02-22 00:15:32 +01:00
committed by teamcity
parent 981f8b1871
commit 8811f62300
77 changed files with 3400 additions and 131 deletions
@@ -3,19 +3,19 @@
// IGNORE_BACKEND: JVM
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T> underlying(a: IC<T>): T = bar(a) {
fun <T: Any> underlying(a: IC<T>): T? = bar(a) {
it.value
}
fun <T> extension(a: IC<T>): T = bar(a) {
fun <T: Any> extension(a: IC<T>): T? = bar(a) {
it.extensionValue()
}
fun <T> dispatch(a: IC<T>): T = bar(a) {
fun <T: Any> dispatch(a: IC<T>): T? = bar(a) {
it.dispatchValue()
}
fun <T> normal(a: IC<T>): T = bar(a) {
fun <T: Any> normal(a: IC<T>): T? = bar(a) {
normalValue(it)
}
@@ -23,26 +23,26 @@ fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun <T> IC<T>.extensionValue(): T = value
fun <T: Any> IC<T>.extensionValue(): T? = value
fun <T> normalValue(ic: IC<T>): T = ic.value
fun <T: Any> normalValue(ic: IC<T>): T? = ic.value
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T>(val value: T) {
fun dispatchValue(): T = value
value class IC<T: Any>(val value: T?) {
fun dispatchValue(): T? = value
}
fun box(): String {
var res = underlying<Int>(IC(40)) + 2
var res = underlying<Int>(IC(40))!! + 2
if (res != 42) "FAIL 1 $res"
res = extension<Int>(IC(40)) + 3
res = extension<Int>(IC(40))!! + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(40)) + 4
res = dispatch<Int>(IC(40))!! + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(40)) + 5
res = normal<Int>(IC(40))!! + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
@@ -0,0 +1,49 @@
// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// IGNORE_BACKEND: JVM
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
fun <T> underlying(a: IC<T>): T = bar(a) {
it.value
}
fun <T> extension(a: IC<T>): T = bar(a) {
it.extensionValue()
}
fun <T> dispatch(a: IC<T>): T = bar(a) {
it.dispatchValue()
}
fun <T> normal(a: IC<T>): T = bar(a) {
normalValue(it)
}
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun <T> IC<T>.extensionValue(): T = value
fun <T> normalValue(ic: IC<T>): T = ic.value
OPTIONAL_JVM_INLINE_ANNOTATION
value class IC<T>(val value: T) {
fun dispatchValue(): T = value
}
fun box(): String {
var res = underlying<Int>(IC(40)) + 2
if (res != 42) "FAIL 1 $res"
res = extension<Int>(IC(40)) + 3
if (res != 43) return "FAIL 2: $res"
res = dispatch<Int>(IC(40)) + 4
if (res != 44) return "FAIL 3: $res"
res = normal<Int>(IC(40)) + 5
if (res != 45) return "FAIL 4: $res"
return "OK"
}