Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/publicApproximation/chainedLambdas.kt
T
Pavel Kirpichenkov dc42b20ae3 [NI] Use alternative to intersection type in public declarations
The new inference uses inferred intersection types normally, unlike the old inference.
However, intersection types in public declarations are approximated to supertype, which
potentially may give a less presice type, then it would be with the OI.
For non-related T1, T2 the NI approximates {T1 & T2} to Any in public declarations,
and if the OI was inferring T1 instead of the intersection type, it may lead to
less precise declaration type and related errors.

The solution is to remember an alternative for an intersection type when present.
Before approximation the alternative replaces the intersection type.

^KT-36249 Fixed
2020-03-05 20:20:47 +03:00

35 lines
692 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
interface First {
fun first() {}
}
interface Second
interface Third
interface Fourth
fun chained1(arg: First) = run {
if (arg !is Second) throw Exception()
arg
}.let { third ->
if (third !is Third) throw Exception()
third
}
fun chained2(arg: First) = run {
if (arg !is Second) throw Exception()
arg
}.let { third ->
if (third !is Third) throw Exception()
third
}.let { fourth ->
if (fourth !is Fourth) throw Exception()
fourth
}
fun test(arg: First) {
chained1(arg).<!NI;UNRESOLVED_REFERENCE!>first<!>()
chained2(arg).<!NI;UNRESOLVED_REFERENCE!>first<!>()
}