[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");