Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/loops/whileNullAssignToSomething.kt
T
Dmitry Savvinov 6065095e24 Fix too aggressive data-flow clearing of loop-assigned vars
This is effectively a revert of
447c127036, which was an (incorrect) fix
for KT-22379.

The bug was that we've cleared data-flow info for assigned variables
*after* knowledge that loop condition if 'false' was applied (we can
claim that if loop has no jump-outs). Therefore, we broke smartcasts in
the innocent code like that:

  var x: Int? = null
  while (x == null) {
      x = readPotentiallyNullableInt()
  }
  // x should be non-null here

Commit reverts that "fix" for 1.3.0 and postpones deprecation until 1.4

KT-22379 Open
KT-27084 Fixed
2018-09-27 12:09:22 +03:00

9 lines
216 B
Kotlin
Vendored

fun main(args: Array<String>) {
var result: String? = null
var i = 0
while (result == null) {
if (i == 10) result = "non null"
else i++
}
<!DEBUG_INFO_SMARTCAST!>result<!>.length
}