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 56892b4c0de..ed873dc655c 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 @@ -31829,6 +31829,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index bf86eb3ff71..5af8257b1f9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -1082,7 +1082,17 @@ public class DescriptorResolver { if (!isPrivate || (isInlineFunction && isAnonymousReturnTypesInPrivateInlineFunctionsForbidden)) { if (type.getConstructor().getSupertypes().size() == 1) { - return type.getConstructor().getSupertypes().iterator().next(); + KotlinType approximatingSuperType = type.getConstructor().getSupertypes().iterator().next(); + KotlinType substitutedSuperType; + MemberScope memberScope = type.getMemberScope(); + + if (memberScope instanceof SubstitutingScope) { + substitutedSuperType = ((SubstitutingScope) memberScope).substitute(approximatingSuperType); + } else { + substitutedSuperType = approximatingSuperType; + } + + return substitutedSuperType; } else { trace.report(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED.on(declaration, type.getConstructor().getSupertypes())); diff --git a/compiler/testData/codegen/box/objects/kt46136.kt b/compiler/testData/codegen/box/objects/kt46136.kt new file mode 100644 index 00000000000..06f64b492aa --- /dev/null +++ b/compiler/testData/codegen/box/objects/kt46136.kt @@ -0,0 +1,13 @@ +// IGNORE_BACKEND_FIR: JVM_IR + +abstract class A { + fun print() = "OK" +} + +fun f() = test("") + +private fun test(t: T) = + object : A() {} + + +fun box() = f().print() 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 5bb23f7033c..ed2d15d70ae 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 @@ -31373,6 +31373,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception { 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 a5a0eaeaef9..9a104651166 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 @@ -31829,6 +31829,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 2818342beb5..5858ce92b54 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -26712,6 +26712,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @TestMetadata("kt535.kt") public void testKt535() throws Exception { runTest("compiler/testData/codegen/box/objects/kt535.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SubstitutingScope.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SubstitutingScope.kt index 7da12970861..b73640908cb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SubstitutingScope.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SubstitutingScope.kt @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.descriptors.Substitutable import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution +import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.safeSubstitute import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize import org.jetbrains.kotlin.utils.sure @@ -35,6 +37,11 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor: private val _allDescriptors by lazy { substitute(workerScope.getContributedDescriptors()) } + fun substitute(type: KotlinType): KotlinType { + if (substitutor.isEmpty) return type + return substitutor.safeSubstitute(type) as KotlinType + } + private fun substitute(descriptor: D): D { if (substitutor.isEmpty) return descriptor diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index b34acf5b177..f54fad66bfb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -22741,6 +22741,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 7c99d1a97f3..287edbc7878 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -22705,6 +22705,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 67edb3bbc04..b43fb1fc6dc 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -19622,6 +19622,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @TestMetadata("kt535.kt") public void testKt535() throws Exception { runTest("compiler/testData/codegen/box/objects/kt535.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 102b885f737..67df341b0ad 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -25450,6 +25450,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/objects/kt45170.kt"); } + @Test + @TestMetadata("kt46136.kt") + public void testKt46136() throws Exception { + runTest("compiler/testData/codegen/box/objects/kt46136.kt"); + } + @Test @TestMetadata("kt535.kt") public void testKt535() throws Exception {