Kapt+JVM_IR: fix error on delegation to anonymous object

In kapt stub generation mode, psi2ir does not generate bodies of
declarations. This means that the delegate type was translated into an
IrType which is based on a class which is not generated by psi2ir, thus
leading to an unbound symbol error. The fix is to avoid using anonymous
types for delegate fields in this mode.

 #KT-59211 Fixed
This commit is contained in:
Alexander Udalov
2023-06-09 16:12:40 +02:00
committed by Space Team
parent fd4e59f279
commit 04998cff8a
5 changed files with 32 additions and 1 deletions
@@ -204,7 +204,9 @@ internal class ClassGenerator(
val delegateType = if (context.configuration.generateBodies) {
getTypeInferredByFrontendOrFail(ktDelegateExpression)
} else {
getTypeInferredByFrontend(ktDelegateExpression) ?: createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktDelegateExpression.text)
getTypeInferredByFrontend(ktDelegateExpression).takeUnless {
it?.constructor?.declarationDescriptor?.let(DescriptorUtils::isLocal) == true
} ?: createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktDelegateExpression.text)
}
val superType = getOrFail(BindingContext.TYPE, ktEntry.typeReference!!)
@@ -0,0 +1,3 @@
interface I
class C : I by (object : I {})
@@ -0,0 +1,14 @@
@kotlin.Metadata()
public final class C implements I {
public C() {
super();
}
}
////////////////////
@kotlin.Metadata()
public abstract interface I {
}
@@ -175,6 +175,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
runTest("plugins/kapt3/kapt3-compiler/testData/converter/delegationAndCompanionObject.kt");
}
@Test
@TestMetadata("delegationToAnonymousObject.kt")
public void testDelegationToAnonymousObject() throws Exception {
runTest("plugins/kapt3/kapt3-compiler/testData/converter/delegationToAnonymousObject.kt");
}
@Test
@TestMetadata("deprecated.kt")
public void testDeprecated() throws Exception {
@@ -175,6 +175,12 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
runTest("plugins/kapt3/kapt3-compiler/testData/converter/delegationAndCompanionObject.kt");
}
@Test
@TestMetadata("delegationToAnonymousObject.kt")
public void testDelegationToAnonymousObject() throws Exception {
runTest("plugins/kapt3/kapt3-compiler/testData/converter/delegationToAnonymousObject.kt");
}
@Test
@TestMetadata("deprecated.kt")
public void testDeprecated() throws Exception {