diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt index 0720f580f09..f2b87e1e6f4 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt @@ -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 diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index fb9b41194ba..61474fc69a0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -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); } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DelegationTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DelegationTranslator.kt index 4760a0d00c8..6fa767504d9 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DelegationTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DelegationTranslator.kt @@ -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) {