From e0d5a5d16795b5f63986eff7f79f289ad7b01889 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 15 Mar 2018 10:52:45 +0300 Subject: [PATCH] Fix some bugs appeared in 610c9b52 * Property references in top-level initializers * Empty String constructor * Special case when inheriting multiple method implementations * Getting IR for error types --- .../konan/descriptors/DescriptorUtils.kt | 38 ++++++++++++++++--- .../konan/irasdescriptors/NewIrUtils.kt | 3 +- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 2 +- .../backend/konan/lower/DelegationLowering.kt | 4 +- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt index c7616a1c1d8..e85e0eab0bb 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt @@ -48,14 +48,42 @@ internal val ClassDescriptor.implementedInterfaces: List * * TODO: this method is actually a part of resolve and probably duplicates another one */ -internal tailrec fun IrSimpleFunction.resolveFakeOverride(): IrSimpleFunction { +internal fun IrSimpleFunction.resolveFakeOverride(): IrSimpleFunction { if (this.isReal) { return this - } else { - return overriddenSymbols - .firstOrNull { it.owner.modality != Modality.ABSTRACT }!! - .owner.resolveFakeOverride() } + + val visited = mutableSetOf() + val realSupers = mutableSetOf() + + fun findRealSupers(function: IrSimpleFunction) { + if (function in visited) return + visited += function + if (function.isReal) { + realSupers += function + } else { + function.overriddenSymbols.forEach { findRealSupers(it.owner) } + } + } + + findRealSupers(this) + + if (realSupers.size > 1) { + visited.clear() + + fun excludeOverridden(function: IrSimpleFunction) { + if (function in visited) return + visited += function + function.overriddenSymbols.forEach { + realSupers.remove(it.owner) + excludeOverridden(it.owner) + } + } + + realSupers.toList().forEach { excludeOverridden(it) } + } + + return realSupers.first { it.modality != Modality.ABSTRACT } } private val intrinsicAnnotation = FqName("konan.internal.Intrinsic") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/NewIrUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/NewIrUtils.kt index d14dd535db6..8914ce520e9 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/NewIrUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/NewIrUtils.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor +import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils @@ -178,7 +179,7 @@ fun IrModuleFragment.referenceAllTypeExternalClassifiers(symbolTable: SymbolTabl fun KotlinType.referenceAllClassifiers() { TypeUtils.getClassDescriptor(this)?.let { - if (it.module != moduleDescriptor) { + if (!ErrorUtils.isError(it) && it.module != moduleDescriptor) { if (it.kind == ClassKind.ENUM_ENTRY) { symbolTable.referenceEnumEntry(it) } else { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 14735df40c9..cc1a0f23c08 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -1990,7 +1990,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map