From 9cf9cb3ecdc3c108ab84a7a12262d5c26c851021 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 11 Jul 2018 11:54:23 +0200 Subject: [PATCH] Fix KotlinType building by IrType: don't miss type parameters of outer for inner class #KT-25405 Fixed --- .../org/jetbrains/kotlin/ir/types/irTypes.kt | 2 +- compiler/testData/codegen/box/ir/kt25405.kt | 31 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 18 +++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 18 +++++++++++ .../LightAnalysisModeTestGenerated.java | 18 +++++++++++ .../IrJsCodegenBoxTestGenerated.java | 18 +++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 18 +++++++++++ 7 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/ir/kt25405.kt diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt index bdb79b6110f..35837148522 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/irTypes.kt @@ -83,7 +83,7 @@ private fun makeKotlinType( val kotlinTypeArguments = arguments.mapIndexed { index, it -> when (it) { is IrTypeProjection -> TypeProjectionImpl(it.variance, it.type.toKotlinType()) - is IrStarProjection -> StarProjectionImpl((classifier.descriptor as ClassDescriptor).declaredTypeParameters[index]) + is IrStarProjection -> StarProjectionImpl((classifier.descriptor as ClassDescriptor).typeConstructor.parameters[index]) else -> error(it) } } diff --git a/compiler/testData/codegen/box/ir/kt25405.kt b/compiler/testData/codegen/box/ir/kt25405.kt new file mode 100644 index 00000000000..1631d7371ad --- /dev/null +++ b/compiler/testData/codegen/box/ir/kt25405.kt @@ -0,0 +1,31 @@ +// IGNORE_BACKEND: JVM_IR + +fun tableView(init: Table.() -> Unit) { + Table().init() +} + +var result = "fail" + +class Table { + + inner class TableColumn(val name: String) { + + } + + fun column(name: String, init: TableColumn.() -> Unit) { + val column = TableColumn(name).init() + } +} + +fun foo() { + tableView { + column("OK") { + result = name + } + } +} + +fun box(): String { + foo() + return result +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 72f1032e887..f0152761af4 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11587,6 +11587,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/ir") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ir extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInIr() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); + } + + @TestMetadata("kt25405.kt") + public void testKt25405() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt25405.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 90765ded41e..93e588b2ce9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11587,6 +11587,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/ir") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ir extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInIr() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("kt25405.kt") + public void testKt25405() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt25405.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ac287dfaa44..63227c1eba5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11587,6 +11587,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/ir") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ir extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInIr() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("kt25405.kt") + public void testKt25405() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt25405.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index ce5c9613fa9..f4bed388215 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -10212,6 +10212,24 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ir") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ir extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInIr() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); + } + + @TestMetadata("kt25405.kt") + public void testKt25405() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt25405.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index f03b98f3cc9..b63d3059fca 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -10212,6 +10212,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ir") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ir extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInIr() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ir"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("kt25405.kt") + public void testKt25405() throws Exception { + runTest("compiler/testData/codegen/box/ir/kt25405.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/javaInterop") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)