Handle incorrect code for interface delegation
#KT-15931 Fixed Target versions 1.1.4
This commit is contained in:
@@ -101,12 +101,11 @@ object CodegenUtil {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getSuperClassBySuperTypeListEntry(specifier: KtSuperTypeListEntry, bindingContext: BindingContext): ClassDescriptor {
|
||||
fun getSuperClassBySuperTypeListEntry(specifier: KtSuperTypeListEntry, bindingContext: BindingContext): ClassDescriptor? {
|
||||
val superType = bindingContext.get(BindingContext.TYPE, specifier.typeReference!!)
|
||||
?: error("superType should not be null: ${specifier.text}")
|
||||
|
||||
return superType.constructor.declarationDescriptor as? ClassDescriptor
|
||||
?: error("ClassDescriptor of superType should not be null: ${specifier.text}")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -1127,17 +1127,22 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
for (KtSuperTypeListEntry specifier : delegationSpecifiers) {
|
||||
if (specifier instanceof KtDelegatedSuperTypeEntry) {
|
||||
KtExpression expression = ((KtDelegatedSuperTypeEntry) specifier).getDelegateExpression();
|
||||
PropertyDescriptor propertyDescriptor = CodegenUtil.getDelegatePropertyIfAny(expression, descriptor, bindingContext);
|
||||
|
||||
PropertyDescriptor propertyDescriptor = expression != null
|
||||
? CodegenUtil.getDelegatePropertyIfAny(expression, descriptor, bindingContext)
|
||||
: null;
|
||||
|
||||
if (CodegenUtil.isFinalPropertyWithBackingField(propertyDescriptor, bindingContext)) {
|
||||
result.addField((KtDelegatedSuperTypeEntry) specifier, propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
KotlinType expressionType = expression != null ? bindingContext.getType(expression) : null;
|
||||
Type asmType =
|
||||
expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier));
|
||||
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, JvmAbi.DELEGATE_SUPER_FIELD_PREFIX + n);
|
||||
KotlinType expressionType = expression != null
|
||||
? bindingContext.getType(expression)
|
||||
: null;
|
||||
ClassDescriptor superClass = getSuperClass(specifier);
|
||||
if (superClass != null) {
|
||||
Type asmType = expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(superClass);
|
||||
result.addField((KtDelegatedSuperTypeEntry) specifier, asmType, JvmAbi.DELEGATE_SUPER_FIELD_PREFIX + n);
|
||||
}
|
||||
}
|
||||
n++;
|
||||
}
|
||||
@@ -1145,7 +1150,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private ClassDescriptor getSuperClass(@NotNull KtSuperTypeListEntry specifier) {
|
||||
return CodegenUtil.getSuperClassBySuperTypeListEntry(specifier, bindingContext);
|
||||
}
|
||||
|
||||
+4
-2
@@ -86,11 +86,13 @@ class DelegationTranslator(
|
||||
|
||||
fun generateDelegated() {
|
||||
for (specifier in delegationBySpecifiers) {
|
||||
generateDelegates(specifier, getSuperClass(specifier), fields[specifier]!!)
|
||||
getSuperClass(specifier)?.let {
|
||||
generateDelegates(specifier, it, fields[specifier]!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSuperClass(specifier: KtSuperTypeListEntry): ClassDescriptor =
|
||||
private fun getSuperClass(specifier: KtSuperTypeListEntry): ClassDescriptor? =
|
||||
CodegenUtil.getSuperClassBySuperTypeListEntry(specifier, bindingContext())
|
||||
|
||||
private fun generateDelegates(specifier: KtSuperTypeListEntry, toClass: ClassDescriptor, field: Field) {
|
||||
|
||||
Reference in New Issue
Block a user