[FE 1.0] Substitute anonymous object's supertypes while using that in public declarations
^KT-46136 Fixed
This commit is contained in:
committed by
teamcity
parent
2c5d817633
commit
3aabc8d666
+6
@@ -31829,6 +31829,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
@@ -1082,7 +1082,17 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
if (!isPrivate || (isInlineFunction && isAnonymousReturnTypesInPrivateInlineFunctionsForbidden)) {
|
if (!isPrivate || (isInlineFunction && isAnonymousReturnTypesInPrivateInlineFunctionsForbidden)) {
|
||||||
if (type.getConstructor().getSupertypes().size() == 1) {
|
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 {
|
else {
|
||||||
trace.report(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED.on(declaration, type.getConstructor().getSupertypes()));
|
trace.report(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED.on(declaration, type.getConstructor().getSupertypes()));
|
||||||
|
|||||||
@@ -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()
|
||||||
+6
@@ -31373,6 +31373,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
+6
@@ -31829,6 +31829,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
+5
@@ -26712,6 +26712,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/objects/kt535.kt");
|
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.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution
|
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.TypeSubstitutor
|
||||||
|
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.safeSubstitute
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
|
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
|
||||||
import org.jetbrains.kotlin.utils.sure
|
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()) }
|
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 {
|
private fun <D : DeclarationDescriptor> substitute(descriptor: D): D {
|
||||||
if (substitutor.isEmpty) return descriptor
|
if (substitutor.isEmpty) return descriptor
|
||||||
|
|
||||||
|
|||||||
+6
@@ -22741,6 +22741,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
+6
@@ -22705,6 +22705,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
+5
@@ -19622,6 +19622,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/objects/kt535.kt");
|
runTest("compiler/testData/codegen/box/objects/kt535.kt");
|
||||||
|
|||||||
+6
@@ -25450,6 +25450,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
|||||||
runTest("compiler/testData/codegen/box/objects/kt45170.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt535.kt")
|
@TestMetadata("kt535.kt")
|
||||||
public void testKt535() throws Exception {
|
public void testKt535() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user