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
@@ -13,9 +13,16 @@ value class Y<T: Number>(val y: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class NX<T: String?>(val x: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class NX2<T: String>(val x: T?)
OPTIONAL_JVM_INLINE_ANNOTATION
value class NY<T: Number?>(val y: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class NY2<T: Number>(val y: T?)
fun testNotNull(x: X<String>?, y: Y<Number>?) {
val xs = listOf<Any?>(x)
val ys = listOf<Any?>(y)
@@ -32,6 +39,14 @@ fun testNullable(x: NX<String?>?, y: NY<Number?>?) {
if (xs[0] === ys[0]) throw AssertionError()
}
fun testNullable2(x: NX2<String>?, y: NY2<Number>?) {
val xs = listOf<Any?>(x)
val ys = listOf<Any?>(y)
if (xs.contains(y)) throw AssertionError()
if (xs[0] == ys[0]) throw AssertionError()
if (xs[0] === ys[0]) throw AssertionError()
}
fun testNullsAsNullable(x: NX<String?>?, y: NY<Number?>?) {
val xs = listOf<Any?>(x)
val ys = listOf<Any?>(y)
@@ -40,6 +55,14 @@ fun testNullsAsNullable(x: NX<String?>?, y: NY<Number?>?) {
if (xs[0] !== ys[0]) throw AssertionError()
}
fun testNullsAsNullable2(x: NX2<String>?, y: NY2<Number>?) {
val xs = listOf<Any?>(x)
val ys = listOf<Any?>(y)
if (!xs.contains(y)) throw AssertionError()
if (xs[0] != ys[0]) throw AssertionError()
if (xs[0] !== ys[0]) throw AssertionError()
}
fun box(): String {
testNotNull(null, null)
@@ -48,7 +71,13 @@ fun box(): String {
testNullable(NX(null), null)
testNullable(null, NY(null))
testNullable2(NX2(null), NY2(null))
testNullable2(NX2(null), null)
testNullable2(null, NY2(null))
testNullsAsNullable(null, null)
testNullsAsNullable2(null, null)
return "OK"
}