JVM IR: skip temporary variables in InventNamesForLocalClasses

This commit is contained in:
Alexander Udalov
2019-08-09 18:15:09 +02:00
parent 312205f376
commit cb2e68fece
8 changed files with 72 additions and 0 deletions
@@ -88,6 +88,15 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
return
}
// We explicitly skip temporary variables (such as a for loop iterator, or a temporary value for an elvis operator)
// because they are not present in the original source code and their names should not affect names of local entities.
if (declaration.origin == IrDeclarationOrigin.FOR_LOOP_ITERATOR ||
declaration.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE
) {
declaration.acceptChildren(this, data)
return
}
val enclosingName = data.enclosingName
val simpleName = declaration.name.asString()
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
fun box(): String {
var result = ""
for (x in listOf('O', 'A', 'K').filter { it > 'D' }) {
result += object { fun run() = x }.run()
}
return result
}
@@ -0,0 +1,3 @@
fun box(): String {
return (object { val r = "OK" } ?: null)!!.r
}
@@ -13789,6 +13789,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("anonymousObjectInForLoopIteratorAndBody.kt")
public void testAnonymousObjectInForLoopIteratorAndBody() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInForLoopIteratorAndBody.kt");
}
@TestMetadata("anonymousObjectInsideElvis.kt")
public void testAnonymousObjectInsideElvis() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInsideElvis.kt");
}
@TestMetadata("classInitializers.kt")
public void testClassInitializers() throws Exception {
runTest("compiler/testData/codegen/box/ir/classInitializers.kt");
@@ -13789,6 +13789,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("anonymousObjectInForLoopIteratorAndBody.kt")
public void testAnonymousObjectInForLoopIteratorAndBody() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInForLoopIteratorAndBody.kt");
}
@TestMetadata("anonymousObjectInsideElvis.kt")
public void testAnonymousObjectInsideElvis() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInsideElvis.kt");
}
@TestMetadata("classInitializers.kt")
public void testClassInitializers() throws Exception {
runTest("compiler/testData/codegen/box/ir/classInitializers.kt");
@@ -12674,6 +12674,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
}
@TestMetadata("anonymousObjectInForLoopIteratorAndBody.kt")
public void testAnonymousObjectInForLoopIteratorAndBody() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInForLoopIteratorAndBody.kt");
}
@TestMetadata("anonymousObjectInsideElvis.kt")
public void testAnonymousObjectInsideElvis() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInsideElvis.kt");
}
@TestMetadata("classInitializers.kt")
public void testClassInitializers() throws Exception {
runTest("compiler/testData/codegen/box/ir/classInitializers.kt");
@@ -11014,6 +11014,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
}
@TestMetadata("anonymousObjectInForLoopIteratorAndBody.kt")
public void testAnonymousObjectInForLoopIteratorAndBody() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInForLoopIteratorAndBody.kt");
}
@TestMetadata("anonymousObjectInsideElvis.kt")
public void testAnonymousObjectInsideElvis() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInsideElvis.kt");
}
@TestMetadata("classInitializers.kt")
public void testClassInitializers() throws Exception {
runTest("compiler/testData/codegen/box/ir/classInitializers.kt");
@@ -12169,6 +12169,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("anonymousObjectInForLoopIteratorAndBody.kt")
public void testAnonymousObjectInForLoopIteratorAndBody() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInForLoopIteratorAndBody.kt");
}
@TestMetadata("anonymousObjectInsideElvis.kt")
public void testAnonymousObjectInsideElvis() throws Exception {
runTest("compiler/testData/codegen/box/ir/anonymousObjectInsideElvis.kt");
}
@TestMetadata("classInitializers.kt")
public void testClassInitializers() throws Exception {
runTest("compiler/testData/codegen/box/ir/classInitializers.kt");