JVM_IR: fix wrong check in skipping captured vars

This commit is contained in:
Georgy Bronnikov
2019-12-11 18:41:57 +03:00
parent 26032e4297
commit bb301f8aca
8 changed files with 42 additions and 1 deletions
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.backend.common.ir.ir2string
import org.jetbrains.kotlin.backend.common.peek import org.jetbrains.kotlin.backend.common.peek
import org.jetbrains.kotlin.backend.common.pop import org.jetbrains.kotlin.backend.common.pop
import org.jetbrains.kotlin.backend.common.push import org.jetbrains.kotlin.backend.common.push
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
@@ -189,7 +190,7 @@ class ClosureAnnotator(irFile: IrFile) {
private fun processMemberAccess(declaration: IrDeclaration) { private fun processMemberAccess(declaration: IrDeclaration) {
if (declaration.isLocal) { if (declaration.isLocal) {
if (declaration is IrSimpleFunction && declaration.parent is IrClass) { if (declaration is IrSimpleFunction && declaration.visibility != Visibilities.LOCAL) {
return return
} }
@@ -0,0 +1,10 @@
// IGNORE_BACKEND_FIR: JVM_IR
class A {
val result: String
init {
val flag = "OK"
fun getFlag(): String = flag
result = { getFlag() } ()
}
}
fun box(): String = A().result
@@ -3966,6 +3966,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
@@ -3966,6 +3966,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
@@ -3946,6 +3946,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
@@ -3946,6 +3946,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
@@ -3291,6 +3291,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
@@ -3291,6 +3291,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt"); runTest("compiler/testData/codegen/box/closures/localClassLambdaClosure.kt");
} }
@TestMetadata("localFunInInit.kt")
public void testLocalFunInInit() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunInInit.kt");
}
@TestMetadata("localFunctionInFunction.kt") @TestMetadata("localFunctionInFunction.kt")
public void testLocalFunctionInFunction() throws Exception { public void testLocalFunctionInFunction() throws Exception {
runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt"); runTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");