K2: Fix processing inference lower bound NullableType <: T & Any

Previously, it was led to plainly adding NullableType <: T constraint
which silently led to successful call completion.
What is suggested is just marking such initial constraint
as unsuccessful.

In K1, the error was reported just via additional type checking
mechanism being run after call completion.

^KT-58665 Fixed
This commit is contained in:
Denis.Zharkov
2023-06-06 13:54:49 +02:00
committed by Space Team
parent 7bc04e2c33
commit 0d070f8ba9
19 changed files with 141 additions and 76 deletions
@@ -1,14 +0,0 @@
// !LANGUAGE: +DefinitelyNonNullableTypes
fun <T> foo(x: T, y: T & Any) = x!!
fun main() {
foo<String>("", "").length
foo<String>("", <!NULL_FOR_NONNULL_TYPE!>null<!>).length
foo<String?>(null, "").length
foo<String?>(null, null).length
foo("", "").length
foo("", null).length
foo(null, "").length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +DefinitelyNonNullableTypes
fun <T> foo(x: T, y: T & Any) = x!!
@@ -28,6 +28,6 @@ fun <F> main(x: F, y: F, z: F, w: F, m: F) {
w1.foo()
w2.foo()
expectNN(m)
expectNN(<!ARGUMENT_TYPE_MISMATCH!>m<!>)
expectNN(m!!)
}
@@ -1,14 +0,0 @@
// !LANGUAGE: +DefinitelyNonNullableTypes
fun <T> foo(x: T, y: T & Any): T & Any = x ?: y
fun main() {
foo<String>("", "").length
foo<String>("", <!NULL_FOR_NONNULL_TYPE!>null<!>).length
foo<String?>(null, "").length
foo<String?>(null, null).length
foo("", "").length
foo("", null).length
foo(null, "").length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +DefinitelyNonNullableTypes
fun <T> foo(x: T, y: T & Any): T & Any = x ?: y