diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 08e6ef9429b..4d81ef2eb16 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -12541,6 +12541,22 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @Nested + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + public class CorrectFrontendCode { + @Test + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index 3f7b6a58d98..27c4fb3fb52 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -195,17 +195,6 @@ open class FirTypeResolveTransformer( return block } - override fun transformDelegatedConstructorCall( - delegatedConstructorCall: FirDelegatedConstructorCall, - data: Any? - ): FirStatement { - delegatedConstructorCall.replaceConstructedTypeRef( - delegatedConstructorCall.constructedTypeRef.transform(this, data) - ) - delegatedConstructorCall.transformCalleeReference(this, data) - return delegatedConstructorCall - } - override fun transformAnnotation(annotation: FirAnnotation, data: Any?): FirStatement { annotation.transformAnnotationTypeRef(this, data) return annotation @@ -230,12 +219,22 @@ open class FirTypeResolveTransformer( firClass: FirClass, data: Any? ): FirStatement { - return withScopeCleanup { - // Otherwise annotations may try to resolve - // themselves as inner classes of the `firClass` - // if their names match + + withScopeCleanup { firClass.transformAnnotations(this, null) + if (firClass is FirRegularClass) { + firClass.addTypeParametersScope() + } + + // ConstructedTypeRef should be resolved only with type parameters, but not with nested classes and classes from supertypes + for (constructor in firClass.declarations.filterIsInstance()) { + constructor.delegatedConstructor?.let(this::resolveConstructedTypeRefForDelegatedConstructorCall) + } + + } + + return withScopeCleanup { // ? Is it Ok to use original file session here ? val superTypes = lookupSuperTypes( firClass, @@ -262,10 +261,20 @@ open class FirTypeResolveTransformer( // Note that annotations are still visited here // again, although there's no need in it - transformElement(firClass, data) as FirClass + transformElement(firClass, data) } } + private fun resolveConstructedTypeRefForDelegatedConstructorCall( + delegatedConstructorCall: FirDelegatedConstructorCall + ) { + delegatedConstructorCall.replaceConstructedTypeRef( + delegatedConstructorCall.constructedTypeRef.transform(this, null) + ) + + delegatedConstructorCall.transformCalleeReference(this, null) + } + private fun FirMemberDeclaration.addTypeParametersScope() { if (typeParameters.isNotEmpty()) { scopes.add(FirMemberTypeParameterScope(this)) diff --git a/compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt b/compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt new file mode 100644 index 00000000000..178ffa4f82e --- /dev/null +++ b/compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt @@ -0,0 +1,11 @@ +open class OtherClass { + fun foo(): String = "OK" + + private class OtherClass {} +} + + +class Derived : OtherClass() + +fun box() = Derived().foo() + diff --git a/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt b/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt deleted file mode 100644 index 4011cf97716..00000000000 --- a/compiler/testData/diagnostics/tests/generics/kt5508.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// KT-5508 Stackoverflow in type substitution - -abstract class A { - public abstract fun foo(x: T) - public abstract fun bar(x: T) - - public inner abstract class B : A>() { - public inner class C : B>() - { - // Here B> means A.B>.B.B.C>>.B.B>.B.B.C>.C> - // while for being a correct override it should be A.B>.B.B.C> - // It happens because at the beginning we search implicit arguments for an outer classes through supertypes - // See TypeResolver.computeImplicitOuterClassArguments for clarifications - override fun foo(x: B>) { - throw UnsupportedOperationException() - } - - override fun bar(x: A.B>.B.B.C>) { - throw UnsupportedOperationException() - } - } - } -} diff --git a/compiler/testData/diagnostics/tests/generics/kt5508.kt b/compiler/testData/diagnostics/tests/generics/kt5508.kt index f1bbe71ad06..01f1b8d13bf 100644 --- a/compiler/testData/diagnostics/tests/generics/kt5508.kt +++ b/compiler/testData/diagnostics/tests/generics/kt5508.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // KT-5508 Stackoverflow in type substitution abstract class A { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index aa3792cd81f..fde8a814fb1 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -12463,6 +12463,22 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + public class CorrectFrontendCode { + @Test + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @Test + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 4ddafb22016..ee7c7323085 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -12541,6 +12541,22 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @Nested + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + public class CorrectFrontendCode { + @Test + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 95ecf83ce1c..92bccf4bbc5 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10053,6 +10053,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CorrectFrontendCode extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index b7aa7edccb6..acba8a68fdd 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -8922,6 +8922,24 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes } } + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CorrectFrontendCode extends AbstractIrJsCodegenBoxES6Test { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath); + } + + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index f2c54ad514e..7ec06fc4438 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -8328,6 +8328,24 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CorrectFrontendCode extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 7bd5e75cd1c..e4d476dcc39 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -8293,6 +8293,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CorrectFrontendCode extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 02890db0fbc..0e966bca5eb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -5634,6 +5634,24 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } + @TestMetadata("compiler/testData/codegen/box/correctFrontendCode") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CorrectFrontendCode extends AbstractIrCodegenBoxWasmTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); + } + + public void testAllFilesPresentInCorrectFrontendCode() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/correctFrontendCode"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + + @TestMetadata("privateNestedClassInSuper.kt") + public void testPrivateNestedClassInSuper() throws Exception { + runTest("compiler/testData/codegen/box/correctFrontendCode/privateNestedClassInSuper.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/dataClasses") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)