Inner type aliases.

Type alias is considered "inner" if it captures outer class type parameters (implicitly or explicitly).
This commit is contained in:
Dmitry Petrov
2016-11-09 13:14:10 +03:00
parent 63fed20249
commit 718e8ebf9e
16 changed files with 244 additions and 27 deletions
@@ -47,14 +47,20 @@ abstract class AbstractTypeAliasDescriptor(
visitor.visitTypeAliasDescriptor(this, data)
override fun isInner(): Boolean =
containingDeclaration !is PackageFragmentDescriptor
// NB: it's ok to use underlyingType here, since referenced inner type aliases also capture type parameters.
// Using expandedType looks "proper", but in fact will cause a recursion in expandedType resolution,
// which will silently produce wrong result.
TypeUtils.contains(underlyingType) {
!it.isError && run {
val constructorDescriptor = it.constructor.declarationDescriptor
constructorDescriptor is TypeParameterDescriptor &&
constructorDescriptor.containingDeclaration != this@AbstractTypeAliasDescriptor
}
}
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> =
declaredTypeParametersImpl
override val classDescriptor: ClassDescriptor?
get() = if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as? ClassDescriptor
override fun getModality() = Modality.FINAL
override fun getVisibility() = visibilityImpl
@@ -133,6 +133,8 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
get() = builtIns.nullableAnyType
override fun getDefaultType(): SimpleType =
builtIns.nullableAnyType
override val classDescriptor: ClassDescriptor?
get() = expandedType.constructor.declarationDescriptor as? ClassDescriptor
override fun substitute(substitutor: TypeSubstitutor) = this
@@ -169,6 +169,9 @@ class DeserializedTypeAliasDescriptor(
defaultTypeImpl = computeDefaultType()
}
override val classDescriptor: ClassDescriptor?
get() = if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as? ClassDescriptor
override fun getDefaultType(): SimpleType =
defaultTypeImpl