Skip to content

Commit

Permalink
[CFG] Fix var initialization check of nested lambdas and trys
Browse files Browse the repository at this point in the history
In deeply nested cases of a try-finally within a lambda, local var
initialization checks can report false positives due to the recent
capture-by-value changes meant for local val initialization checks.

^KT-70133 Fixed
  • Loading branch information
bnorm authored and qodana-bot committed Aug 12, 2024
1 parent 60d0890 commit 373487a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ class PropertyInitializationInfoCollector(
data: PathAwarePropertyInitializationInfo
): PathAwarePropertyInitializationInfo {
val result = super.visitEdge(from, to, metadata, data)
if (metadata.label == CapturedByValue) {
// Remove properties from data that are not captured by value.
val invalidProperties = data.flatMapTo(hashSetOf()) { it.value.keys }.filter { !it.isCapturedByValue }
return invalidProperties.fold(result) { filteredData, symbol ->
filteredData.removeRange(symbol)
}
}
if (!metadata.kind.isBack) return result
val declaredVariableSymbolsInCapturedScope = when {
from is PostponedLambdaExitNode -> declaredVariablesInLoop[from.fir.anonymousFunction]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// FIR_IDENTICAL
fun invokeLater(x: () -> Unit) {
x()
}

fun nestedFinallyAndLambda1() {
var x: String
invokeLater {
x = ""
invokeLater {
try {
} finally {
x.length
}
}
}
}

fun nestedFinallyAndLambda2() {
var x: String
invokeLater {
x = ""
try {
} finally {
invokeLater {
x.length
}
}
}
}

fun nestedFinallyAndLambda3() {
var x: String
try {
} finally {
invokeLater {
x = ""
invokeLater {
x.length
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 373487a

Please sign in to comment.