Var can be val: correct handling of initialization in lambda #KT-14065 Fixed
This commit is contained in:
@@ -83,7 +83,7 @@ class CanBeValInspection : AbstractKotlinInspection() {
|
|||||||
val writeInstructions = pseudocode.collectWriteInstructions(descriptor)
|
val writeInstructions = pseudocode.collectWriteInstructions(descriptor)
|
||||||
if (writeInstructions.isEmpty()) return false // incorrect code - do not report
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user