Kapt+JVM_IR: generate delegated members correctly
Generate a declaration for each delegated member without body. If we don't generate delegated declarations, subclasses will have incorrect IR with unbound symbols in fake overrides. #KT-58027 Fixed
This commit is contained in:
committed by
Space Team
parent
5407ac1c72
commit
bc7aea1426
@@ -151,7 +151,11 @@ class DelegationResolver<T : CallableMemberDescriptor> private constructor(
|
||||
// descriptor = Foo
|
||||
// toInterface = Bar
|
||||
// delegateExpressionType = typeof(baz)
|
||||
// return Map<member of Foo, corresponding member of typeOf(baz)>
|
||||
//
|
||||
// This method returns a map where keys are members of Foo, and values are members of typeof(baz).
|
||||
//
|
||||
// In case delegation is to an error type, which is useful for KAPT stub generation mode, typeof(baz) has no members, so we return
|
||||
// a map from each element to it (so keys = values in the returned map).
|
||||
fun getDelegates(
|
||||
descriptor: ClassDescriptor,
|
||||
toInterface: ClassDescriptor,
|
||||
@@ -175,18 +179,22 @@ class DelegationResolver<T : CallableMemberDescriptor> private constructor(
|
||||
val actualDelegates = DescriptorUtils.getAllOverriddenDescriptors(delegatingMember)
|
||||
.filter { it.containingDeclaration == toInterface }
|
||||
.map { overriddenDescriptor ->
|
||||
val name = overriddenDescriptor.name
|
||||
// this is the actual member of delegateExpressionType that we are delegating to
|
||||
(scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_OVERRIDES) +
|
||||
scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_OVERRIDES))
|
||||
.firstOrNull {
|
||||
it == overriddenDescriptor || OverridingUtil.overrides(
|
||||
it,
|
||||
overriddenDescriptor,
|
||||
it.module.isTypeRefinementEnabled(),
|
||||
true
|
||||
)
|
||||
}
|
||||
if (scopeType.isError) {
|
||||
overriddenDescriptor
|
||||
} else {
|
||||
val name = overriddenDescriptor.name
|
||||
// This is the actual member of delegateExpressionType that we are delegating to.
|
||||
(scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_OVERRIDES) +
|
||||
scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_OVERRIDES))
|
||||
.firstOrNull {
|
||||
it == overriddenDescriptor || OverridingUtil.overrides(
|
||||
it,
|
||||
overriddenDescriptor,
|
||||
it.module.isTypeRefinementEnabled(),
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actualDelegates.firstOrNull()
|
||||
|
||||
@@ -324,7 +324,9 @@ internal class ClassGenerator(
|
||||
// TODO could possibly refer to scoped type parameters for property accessors
|
||||
irFunction.returnType = delegatedDescriptor.returnType!!.toIrType()
|
||||
|
||||
irFunction.body = generateDelegateFunctionBody(irDelegate, delegatedDescriptor, delegateToDescriptor, irFunction)
|
||||
if (context.configuration.generateBodies) {
|
||||
irFunction.body = generateDelegateFunctionBody(irDelegate, delegatedDescriptor, delegateToDescriptor, irFunction)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateDelegateFunctionBody(
|
||||
|
||||
Reference in New Issue
Block a user