Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/variables/reassignedDependency.fir.kt
T
pyos 2ae06a8d46 FIR DFA: when removing a variable, move type statements about dependents
val c = C("...")
  val d = c
  if (c.x == null) return
  c.x.length // c.x has type String
  d.x.length // d.x -> c.x through d -> c
  c = C(null) // remove alias d -> c
  d.x.length // info from c.x moved to d.x

^KT-54824 Fixed
2022-11-22 15:44:26 +00:00

78 lines
1.4 KiB
Kotlin
Vendored

// SKIP_TXT
class C(val x: String?)
fun test1() {
var c = C("...")
val x = c.x
if (x == null) return
x.length // ok
c.x.length // ok
c = C(null)
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
}
fun test2() {
var c = C("...")
val x = c.x
if (x == null) return
while (true) {
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
c = C(null)
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
}
}
fun test3(p: Boolean) {
var c = C("...")
val x = c.x
if (x == null) return
x.length // ok
c.x.length // ok
if (p) {
c = C(null)
}
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
}
fun test4(p: Boolean, q: Boolean) {
var c = C("...")
val x = c.x
if (x == null) return
x.length // ok
c.x.length // ok
if (p) {
if (q) {
c = C(null)
} else {
c = C(null)
}
} else {
if (q) {
c = C(null)
} else {
c = C(null)
}
}
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
}
fun test5() {
var c = C("...")
val d = c
val x = d.x
if (x == null) return
x.length // ok
c.x.length // ok
d.x.length // ok
c = C(null)
x.length // ok
c.x<!UNSAFE_CALL!>.<!>length // bad
d.x.length // ok
}