IR: Do not capture variables from method calls in ClosureAnnotator
To call a method of a class, you never need to supply any values of local variables (they would always be provided to the constructor).
This commit is contained in:
+4
@@ -189,6 +189,10 @@ class ClosureAnnotator(irFile: IrFile) {
|
||||
|
||||
private fun processMemberAccess(declaration: IrDeclaration) {
|
||||
if (declaration.isLocal) {
|
||||
if (declaration is IrSimpleFunction && declaration.parent is IrClass) {
|
||||
return
|
||||
}
|
||||
|
||||
val builder = closureBuilders[declaration]
|
||||
builder?.let {
|
||||
closuresStack.peek()?.include(builder)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
class C {
|
||||
|
||||
val s = "OK"
|
||||
|
||||
private val localObject = object {
|
||||
fun getS(): String {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
fun ok(): String =
|
||||
33.let { localObject.getS() }
|
||||
}
|
||||
|
||||
fun box() = C().ok()
|
||||
+5
@@ -17146,6 +17146,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
+5
@@ -17146,6 +17146,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
+5
@@ -15996,6 +15996,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
+5
@@ -15996,6 +15996,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
Generated
+5
@@ -13126,6 +13126,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
+5
@@ -14266,6 +14266,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClass.kt")
|
||||
public void testObjectLiteralInClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralInClosure.kt")
|
||||
public void testObjectLiteralInClosure() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/objects/objectLiteralInClosure.kt");
|
||||
|
||||
Reference in New Issue
Block a user