Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/safecalls/nullableReceiverWithFlexible.fir.kt
T
Jinseong Jeon e72ddbcbfe FIR checker: differentiate UNSAFE_CALL from INAPPLICABLE_CANDIDATE
To do so, inside the root cause of inapplicable candidate errors,
we will record expected/actual type of receiver, if any.
That will help identifying inapplicable calls on nullable receiver.
2021-01-29 16:54:23 +03:00

25 lines
505 B
Kotlin
Vendored

// FILE: Foo.java
public class Foo {
public String bar;
private Foo(String bar) {
this.bar = bar;
}
public static Foo create(String bar) {
return new Foo(bar);
}
}
// FILE: Test.kt
fun test() {
val foo = Foo.create(null)
foo?.bar.let {
// Error, foo?.bar is nullable
it.<!UNSAFE_CALL!>length<!>
// Foo is nullable but flexible, so call is considered safe here
foo.bar.length
// Correct
foo?.bar?.length
}
}