IR: skip script inner classes in LDL

#KT-49012 fixed
This commit is contained in:
Ilya Chernikov
2021-09-30 13:57:49 +02:00
parent 7e86f5dcd9
commit fd2929d2c5
4 changed files with 43 additions and 0 deletions
@@ -953,6 +953,8 @@ class LocalDeclarationsLowering(
super.visitConstructor(declaration, data)
if (!isScriptMode && !declaration.constructedClass.isLocalNotInner()) return
// Inner classes in scripts are handled properly in the InnerClassesLowering
if (isScriptMode && declaration.constructedClass.isInner) return
// LDL doesn't work on the enums because local enums are not allowed, so skipping them in scripts too
if (isScriptMode && declaration.constructedClass.kind == ClassKind.ENUM_CLASS) return
@@ -964,6 +966,8 @@ class LocalDeclarationsLowering(
super.visitClass(declaration, data.withCurrentClass(declaration))
if (!isScriptMode && !declaration.isLocalNotInner()) return
// Inner classes in scripts are handled properly in the InnerClassesLowering
if (isScriptMode && declaration.isInner) return
// LDL doesn't work on the enums because local enums are not allowed, so skipping them in scripts too
if (isScriptMode && declaration.kind == ClassKind.ENUM_CLASS) return
+29
View File
@@ -0,0 +1,29 @@
val b = "K"
inner class InnerClass(val s: String) {
fun test1() = s + b
inner class C1 {
fun bar(c: String) = s + b + c
}
fun test2() = C1().bar("!")
inner class C2 {
fun bar(c: String) = s + b + c
fun test(): String {
var c = "?"
return object {
fun run() = s + b + c
}.run()
}
}
fun test3() = C2().test()
}
val rv = InnerClass("O").test1() + InnerClass("_O").test2() + InnerClass("__O").test3()
// expected: rv: OK_OK!__OK?
@@ -64,6 +64,11 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
runTest("compiler/testData/codegen/script/inline.kts");
}
@TestMetadata("innerClass.kts")
public void testInnerClass() throws Exception {
runTest("compiler/testData/codegen/script/innerClass.kts");
}
@TestMetadata("kt20707.kts")
public void testKt20707() throws Exception {
runTest("compiler/testData/codegen/script/kt20707.kts");
@@ -65,6 +65,11 @@ public class IrScriptCodegenTestGenerated extends AbstractIrScriptCodegenTest {
runTest("compiler/testData/codegen/script/inline.kts");
}
@TestMetadata("innerClass.kts")
public void testInnerClass() throws Exception {
runTest("compiler/testData/codegen/script/innerClass.kts");
}
@TestMetadata("kt20707.kts")
public void testKt20707() throws Exception {
runTest("compiler/testData/codegen/script/kt20707.kts");