FE1.0: keep nullability when approximating local types (in 1.9)

Report an error that inference will change and type has to be provided
manually in other language versions, since the current behavior is an
unsoundness that can cause runtime NPEs while the new behavior may
silently change overload resolution.

^KT-30054 Fixed
This commit is contained in:
pyos
2022-09-12 12:59:42 +02:00
committed by teamcity
parent 062308c7c1
commit adcbc5ec99
9 changed files with 44 additions and 3 deletions
@@ -1,4 +1,6 @@
// ISSUE: KT-30054
// FIR_IDENTICAL
// !LANGUAGE: +KeepNullabilityWhenApproximatingLocalType
interface I {
fun foo(): String
}
@@ -13,6 +15,6 @@ fun bar(condition: Boolean) /*: I? */ =
fun main() {
bar(false).<!UNRESOLVED_REFERENCE!>baz<!>()
bar(false).foo()
bar(false)<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
bar(false)<!UNSAFE_CALL!>.<!>foo()
bar(false)?.foo()
}
@@ -1,6 +1,6 @@
package
public fun bar(/*0*/ condition: kotlin.Boolean): I
public fun bar(/*0*/ condition: kotlin.Boolean): I?
public fun main(): kotlin.Unit
public interface I {
@@ -0,0 +1,18 @@
// ISSUE: KT-30054
interface I {
fun foo(): String
}
<!APPROXIMATED_LOCAL_TYPE_WILL_BECOME_NULLABLE!>fun bar(condition: Boolean)<!> /*: I? */ =
if (condition)
object : I {
override fun foo() = "should check for null first"
fun baz() = "invisible"
}
else null
fun main() {
bar(false).<!UNRESOLVED_REFERENCE!>baz<!>()
bar(false).foo()
bar(false)<!UNNECESSARY_SAFE_CALL!>?.<!>foo()
}
@@ -0,0 +1,11 @@
package
public fun bar(/*0*/ condition: kotlin.Boolean): I
public fun main(): kotlin.Unit
public interface I {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}