[FE 1.0] Substitute anonymous object's supertypes while using that in public declarations

^KT-46136 Fixed
This commit is contained in:
Victor Petukhov
2022-02-21 16:18:19 +03:00
committed by teamcity
parent 2c5d817633
commit 3aabc8d666
11 changed files with 77 additions and 1 deletions
@@ -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 {
@@ -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()));
+13
View File
@@ -0,0 +1,13 @@
// IGNORE_BACKEND_FIR: JVM_IR
abstract class A<T> {
fun print() = "OK"
}
fun f() = test("")
private fun <T> test(t: T) =
object : A<T>() {}
fun box() = f().print()
@@ -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 {
@@ -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 {
@@ -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");
@@ -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 <D : DeclarationDescriptor> substitute(descriptor: D): D {
if (substitutor.isEmpty) return descriptor
@@ -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 {
@@ -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 {
@@ -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");
@@ -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 {