Files
kotlin-fork/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/externalArguments.kt
T
Pavel Kirpichenkov 07ca355af8 [NI] Fix smartcasts for conventional contains in when
Call argument for conventional `contains` after expanding `in` may come from a `when` subject during its branch analysis.
In this case data flow info from a previous when branch was not considered,
because data flow info for subject had been used instead of data flow before argument.
Use of the latter one for the conventional `contains` solves the issue.

The old FE uses `isExternal` property of value arguments to skip smartcast reporting on `when` subject,
if they come from branches. To prevent undesired smartcasts on `when` subject after branch analysis in the new FE,
`isExternal` arguments are skipped in diagnostic reporter and during recorded type update.

Also, the new FE interprets `isExternal` completely differently from the old FE.
In the old FE this property is used exclusively by `when` with subject.
In the new FE it is also used for parially resolved calls, lambda return arguments and receivers.
This may be preventing the use of data flow info before argument in the first place, but this assumption requires additional investigation.

^KT-36818 Fixed
2020-02-20 19:07:54 +03:00

38 lines
779 B
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
fun testLambdaArgumentSmartCast(foo: Int?) {
val v = run {
if (foo != null)
return@run <!NI;DEBUG_INFO_SMARTCAST!>foo<!>
15
}
}
class D {
operator fun getValue(ref: Any?, property: KProperty<*>): Int = 42
}
fun testSmartCastInDelegate(d: D?) {
if (d == null) return
val v: Int by <!DEBUG_INFO_SMARTCAST!>d<!>
}
fun testFunctionCallSmartcast(fn: (() -> Unit)?) {
if (fn == null) return
<!DEBUG_INFO_SMARTCAST!>fn<!>()
}
fun testCallableRefernceSmartCast() {
fun forReference() {}
val refernece = if (true) ::forReference else null
if (refernece == null)
return
<!DEBUG_INFO_SMARTCAST!>refernece<!>()
}