diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt index ed2c14d55f9..b1b1a968a73 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.commonizer.isUnderStandardKotlinPackages import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSimpleTypeKind.Companion.areCompatible +import org.jetbrains.kotlin.descriptors.commonizer.resolveClassOrTypeAliasByFqName import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName @@ -18,7 +19,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.KotlinTypeFactory.flexibleType import org.jetbrains.kotlin.types.KotlinTypeFactory.simpleType -import org.jetbrains.kotlin.utils.addToStdlib.cast internal fun List.buildDescriptorsAndTypeParameterResolver( targetComponents: TargetDeclarationsBuilderComponents, @@ -142,10 +142,7 @@ internal fun findClassOrTypeAlias( val builtInsModule = targetComponents.builtIns.builtInsModule // TODO: this works fine for Native as far as built-ins module contains full Native stdlib, but this is not enough for JVM and JS - builtInsModule.getPackage(fqName.parent()) - .memberScope - .getContributedClassifier(fqName.shortName(), NoLookupLocation.FOR_ALREADY_TRACKED) - ?.cast() + builtInsModule.resolveClassOrTypeAliasByFqName(fqName, NoLookupLocation.FOR_ALREADY_TRACKED) ?: error("Classifier $fqName not found in built-ins module $builtInsModule") } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils.kt index 2bc3cb2f868..c691658b83d 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils.kt @@ -6,9 +6,12 @@ package org.jetbrains.kotlin.descriptors.commonizer import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl +import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.konan.library.KonanFactories.DefaultDeserializedDescriptorFactory import org.jetbrains.kotlin.konan.library.KonanFactories.createDefaultKonanResolvedModuleDescriptorsFactory import org.jetbrains.kotlin.name.FqName @@ -125,3 +128,20 @@ internal fun createKotlinNativeForwardDeclarationsModule( builtIns = builtIns, storageManager = storageManager ) + +// similar to org.jetbrains.kotlin.descriptors.DescriptorUtilKt#resolveClassByFqName, but resolves also type aliases +internal fun ModuleDescriptor.resolveClassOrTypeAliasByFqName( + fqName: FqName, + lookupLocation: LookupLocation +): ClassifierDescriptorWithTypeParameters? { + if (fqName.isRoot) return null + + (getPackage(fqName.parent()).memberScope.getContributedClassifier( + fqName.shortName(), + lookupLocation + ) as? ClassifierDescriptorWithTypeParameters)?.let { return it } + + return (resolveClassOrTypeAliasByFqName(fqName.parent(), lookupLocation) as? ClassDescriptor) + ?.unsubstitutedInnerClassesScope + ?.getContributedClassifier(fqName.shortName(), lookupLocation) as? ClassifierDescriptorWithTypeParameters +}