Do not eagerly compute deserialized typealias constructors
Otherwise, when adding a typealias to core/builtins, it leads to an exception "JvmBuiltins instance has not been initialized properly". It happens because we start computing typealias constructors even before the compiler has been initialized properly. Basically we're creating the container, and as a part of it, we're computing default imports, and for that we need to get all top-level classifiers from scopes imported by default, which includes typealiases. Eager call to `getTypeAliasConstructors` here results in computing constructors of the class descriptor on the RHS of the type alias, which is not possible if that class is built-in, since the container has not yet been created and thus `JvmBuiltIns` has not been initialized yet. No tests added, and no issue is affected because, as mentioned above, the problem is only reproducible if we add something to core/builtins.
This commit is contained in:
+2
-2
@@ -32,14 +32,14 @@ import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
class LazyTypeAliasDescriptor(
|
||||
override val storageManager: StorageManager,
|
||||
storageManager: StorageManager,
|
||||
private val trace: BindingTrace,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
sourceElement: SourceElement,
|
||||
visibility: DescriptorVisibility
|
||||
) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, sourceElement, visibility),
|
||||
) : AbstractTypeAliasDescriptor(storageManager, containingDeclaration, annotations, name, sourceElement, visibility),
|
||||
TypeAliasDescriptor {
|
||||
override val constructors: Collection<TypeAliasConstructorDescriptor> by storageManager.createLazyValue {
|
||||
getTypeAliasConstructors()
|
||||
|
||||
+5
-3
@@ -23,11 +23,12 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.TypeRefinement
|
||||
|
||||
abstract class AbstractTypeAliasDescriptor(
|
||||
protected val storageManager: StorageManager,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
@@ -35,8 +36,9 @@ abstract class AbstractTypeAliasDescriptor(
|
||||
private val visibilityImpl: DescriptorVisibility
|
||||
) : DeclarationDescriptorNonRootImpl(containingDeclaration, annotations, name, sourceElement),
|
||||
TypeAliasDescriptor {
|
||||
|
||||
protected abstract val storageManager: StorageManager
|
||||
override val constructors: Collection<TypeAliasConstructorDescriptor> by storageManager.createLazyValue {
|
||||
getTypeAliasConstructors()
|
||||
}
|
||||
|
||||
// TODO kotlinize some interfaces
|
||||
private lateinit var declaredTypeParametersImpl: List<TypeParameterDescriptor>
|
||||
|
||||
+11
-13
@@ -155,19 +155,18 @@ class DeserializedClassConstructorDescriptor(
|
||||
}
|
||||
|
||||
class DeserializedTypeAliasDescriptor(
|
||||
override val storageManager: StorageManager,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
override val proto: ProtoBuf.TypeAlias,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, SourceElement.NO_SOURCE, visibility),
|
||||
storageManager: StorageManager,
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
annotations: Annotations,
|
||||
name: Name,
|
||||
visibility: DescriptorVisibility,
|
||||
override val proto: ProtoBuf.TypeAlias,
|
||||
override val nameResolver: NameResolver,
|
||||
override val typeTable: TypeTable,
|
||||
override val versionRequirementTable: VersionRequirementTable,
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
) : AbstractTypeAliasDescriptor(storageManager, containingDeclaration, annotations, name, SourceElement.NO_SOURCE, visibility),
|
||||
DeserializedMemberDescriptor {
|
||||
override lateinit var constructors: Collection<TypeAliasConstructorDescriptor> private set
|
||||
|
||||
override lateinit var underlyingType: SimpleType private set
|
||||
override lateinit var expandedType: SimpleType private set
|
||||
@@ -184,7 +183,6 @@ class DeserializedTypeAliasDescriptor(
|
||||
this.expandedType = expandedType
|
||||
typeConstructorParameters = computeConstructorTypeParameters()
|
||||
defaultTypeImpl = computeDefaultType()
|
||||
constructors = getTypeAliasConstructors()
|
||||
}
|
||||
|
||||
override val classDescriptor: ClassDescriptor?
|
||||
|
||||
Reference in New Issue
Block a user