Var can be val: correct handling of initialization in lambda #KT-14065 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-10-25 15:06:02 +03:00
parent fd9e59ac7b
commit 66f3e266d9
2 changed files with 10 additions and 1 deletions
@@ -83,7 +83,7 @@ class CanBeValInspection : AbstractKotlinInspection() {
val writeInstructions = pseudocode.collectWriteInstructions(descriptor)
if (writeInstructions.isEmpty()) return false // incorrect code - do not report
return writeInstructions.none { canReach(it, writeInstructions) }
return writeInstructions.none { it.owner !== pseudocode || canReach(it, writeInstructions) }
}
}
@@ -0,0 +1,9 @@
fun run(f: () -> Unit) = f()
fun foo() {
var a: Int
run {
a = 20
}
}