diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 7cfad910b6f..11950049d6f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -220,7 +220,8 @@ class ExpressionCodegen( if (expression.isTransparentScope) return super.visitBlock(expression, data) val info = data.create() - return super.visitBlock(expression, info).apply { + // Force materialization to avoid reading from out-of-scope variables. + return super.visitBlock(expression, info).materialized.apply { writeLocalVariablesInTable(info) } }