[Commonizer] Fix: Correct resolution of nested classes
This commit is contained in:
@@ -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<CirTypeParameter>.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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user