Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/exclExclInference.kt
T
Denis.Zharkov 56557fb8ff K2: Fix generic inference case with !! synthetic call
Result of the `checkNotNull` calls should always be a non-nullable
values.
The simplest idea how to acheive it is adding not-nullable Any bound
to the type parameter declaration.

Existing comment stating about impossibility of such bound seems to be
not 100% correct because it doesn't take into account presence of
definitely-non-nullable X & Any types that allow described case with
nullable generic.

^KT-55804 Fixed
2023-04-03 12:44:52 +00:00

18 lines
427 B
Kotlin
Vendored

// FIR_DUMP
// ISSUE: KT-55804
fun foo() {
val x: String?
x = materialize()!! // Should be treated as non-nullable assignment
<!DEBUG_INFO_SMARTCAST!>x<!>.length // Should be allowed
}
fun <E> materialize(): E = TODO()
fun <F> test(f: F) = f!!
fun main() {
test<String>("").length
test<String?>(null).length // `.length` should be allowed because return type of "test" should be inferred to `F & Any`
}