KT-11960: add test for case of instantiating inner class of a local class
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Enable for JVM backend when KT-8120 gets fixed
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class C() {
|
||||
val y = t
|
||||
|
||||
inner class D() {
|
||||
fun copyOuter() = C()
|
||||
}
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = C()
|
||||
}
|
||||
|
||||
val c = (s as C).D().copyOuter()
|
||||
log += c.y
|
||||
}
|
||||
|
||||
if (log != "111") return "fail: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class A() {
|
||||
fun foo() = { t }
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = A()
|
||||
}
|
||||
|
||||
log += (s as A).foo()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail1: ${log}"
|
||||
|
||||
s = null
|
||||
log = ""
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class B() {
|
||||
val y = t
|
||||
|
||||
fun foo() = { y }
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = B()
|
||||
}
|
||||
|
||||
log += (s as B).foo()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail2: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// Enable when KT-12566 gets fixed
|
||||
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
class C() {
|
||||
val y = t
|
||||
|
||||
inner class D() {
|
||||
fun foo() = "($y;$t)"
|
||||
}
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = C()
|
||||
}
|
||||
|
||||
log += (s as C).D().foo()
|
||||
}
|
||||
|
||||
if (log != "(1;1)(1;1)(1;1)") return "fail: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -7863,6 +7863,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class LocalClasses extends AbstractBlackBoxCodegenTest {
|
||||
@TestMetadata("closureOfInnerLocalClass.kt")
|
||||
public void ignoredClosureOfInnerLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureOfInnerLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureWithSelfInstantiation.kt")
|
||||
public void ignoredClosureWithSelfInstantiation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureWithSelfInstantiation.kt");
|
||||
@@ -7885,6 +7891,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureOfLambdaInLocalClass.kt")
|
||||
public void testClosureOfLambdaInLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureOfLambdaInLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inExtensionFunction.kt")
|
||||
public void testInExtensionFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/inExtensionFunction.kt");
|
||||
@@ -8005,6 +8017,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ownClosureOfInnerLocalClass.kt")
|
||||
public void testOwnClosureOfInnerLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/ownClosureOfInnerLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withclosure.kt")
|
||||
public void testWithclosure() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/withclosure.kt");
|
||||
|
||||
@@ -187,4 +187,8 @@ public final class ClosureTest extends SingleFileTranslationTest {
|
||||
public void testClosureThisInLambdaInsideObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testLambdaInLocalFun() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -31,6 +31,12 @@ import java.util.regex.Pattern;
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class LocalClassesTestGenerated extends AbstractLocalClassesTest {
|
||||
@TestMetadata("ownClosureOfInnerLocalClass.kt")
|
||||
public void ignoredOwnClosureOfInnerLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/ownClosureOfInnerLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLocalClasses() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/localClasses"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
@@ -47,6 +53,18 @@ public class LocalClassesTestGenerated extends AbstractLocalClassesTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureOfInnerLocalClass.kt")
|
||||
public void testClosureOfInnerLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureOfInnerLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureOfLambdaInLocalClass.kt")
|
||||
public void testClosureOfLambdaInLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureOfLambdaInLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("closureWithSelfInstantiation.kt")
|
||||
public void testClosureWithSelfInstantiation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureWithSelfInstantiation.kt");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var log = ""
|
||||
|
||||
var s: Any? = null
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
fun foo() = {
|
||||
fun q() = { t }
|
||||
q()
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = foo()
|
||||
}
|
||||
|
||||
log += (s as (() -> (() -> String)))()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail1: ${log}"
|
||||
|
||||
s = null
|
||||
log = ""
|
||||
for (t in arrayOf("1", "2", "3")) {
|
||||
fun foo() = {
|
||||
val y = t
|
||||
fun q() = { y }
|
||||
q()
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = foo()
|
||||
}
|
||||
|
||||
log += (s as (() -> (() -> String)))()()
|
||||
}
|
||||
|
||||
if (log != "111") return "fail2: ${log}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user