[FIR] Lambda reassigned arguments should not have contracts applied

When applying function contracts to arguments, make sure the argument
variable hasn't been reassigned within a lambda. Contracts can only be
applied to unchanged variables, otherwise outdated type statements could
be added to the variable.

^KT-63151 Fixed
This commit is contained in:
Brian Norman
2024-01-26 09:18:55 -06:00
committed by Space Team
parent a2c9e5b36a
commit 76b9ba05fd
2 changed files with 26 additions and 11 deletions
@@ -46,6 +46,6 @@ fun safeCall() {
fun contractFunction() {
var x: String? = ""
if (isNotNullAlsoCall(x) { x = null }) {
x.length // bad (#2 == true => x#0 != null; but this is x#1 = null)
x<!UNSAFE_CALL!>.<!>length // bad (#2 == true => x#0 != null; but this is x#1 = null)
}
}