Containing declaration for TypeAliasConstructorDescriptor
is a corresponding TypeAliasDescriptor.
This commit is contained in:
committed by
Dmitry Petrov
parent
1cc7f19d10
commit
b31ab729de
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.cfg.WhenMissingCase
|
import org.jetbrains.kotlin.cfg.WhenMissingCase
|
||||||
import org.jetbrains.kotlin.cfg.hasUnknown
|
import org.jetbrains.kotlin.cfg.hasUnknown
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newTable
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.newText
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
@@ -85,7 +86,9 @@ object Renderers {
|
|||||||
val declarationKindWithSpace = when (it) {
|
val declarationKindWithSpace = when (it) {
|
||||||
is PackageFragmentDescriptor -> "package "
|
is PackageFragmentDescriptor -> "package "
|
||||||
is ClassDescriptor -> "${it.renderKind()} "
|
is ClassDescriptor -> "${it.renderKind()} "
|
||||||
|
is TypeAliasDescriptor -> "typealias "
|
||||||
is ConstructorDescriptor -> "constructor "
|
is ConstructorDescriptor -> "constructor "
|
||||||
|
is TypeAliasConstructorDescriptor -> "typealias constructor "
|
||||||
is PropertyGetterDescriptor -> "property getter "
|
is PropertyGetterDescriptor -> "property getter "
|
||||||
is PropertySetterDescriptor -> "property setter "
|
is PropertySetterDescriptor -> "property setter "
|
||||||
is FunctionDescriptor -> "function "
|
is FunctionDescriptor -> "function "
|
||||||
|
|||||||
@@ -90,8 +90,7 @@ class OverloadChecker(val specificityComparator: TypeSpecificityComparator) {
|
|||||||
DeclarationCategory.EXTENSION_PROPERTY
|
DeclarationCategory.EXTENSION_PROPERTY
|
||||||
else
|
else
|
||||||
DeclarationCategory.TYPE_OR_VALUE
|
DeclarationCategory.TYPE_OR_VALUE
|
||||||
is ConstructorDescriptor,
|
is FunctionDescriptor ->
|
||||||
is SimpleFunctionDescriptor ->
|
|
||||||
DeclarationCategory.FUNCTION
|
DeclarationCategory.FUNCTION
|
||||||
is ClassifierDescriptor ->
|
is ClassifierDescriptor ->
|
||||||
DeclarationCategory.TYPE_OR_VALUE
|
DeclarationCategory.TYPE_OR_VALUE
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ class OverloadResolver(
|
|||||||
checkOverloadsInPackages(c)
|
checkOverloadsInPackages(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findConstructorsInNestedClassesAndTypeAliases(c: BodiesResolveContext): MultiMap<ClassDescriptor, ConstructorDescriptor> {
|
private fun findConstructorsInNestedClassesAndTypeAliases(c: BodiesResolveContext): MultiMap<ClassDescriptor, FunctionDescriptor> {
|
||||||
val constructorsByOuterClass = MultiMap.create<ClassDescriptor, ConstructorDescriptor>()
|
val constructorsByOuterClass = MultiMap.create<ClassDescriptor, FunctionDescriptor>()
|
||||||
|
|
||||||
for (klass in c.declaredClasses.values) {
|
for (klass in c.declaredClasses.values) {
|
||||||
if (klass.kind.isSingleton || klass.name.isSpecial) {
|
if (klass.kind.isSingleton || klass.name.isSpecial) {
|
||||||
@@ -83,7 +83,7 @@ class OverloadResolver(
|
|||||||
|
|
||||||
private fun checkOverloadsInClass(
|
private fun checkOverloadsInClass(
|
||||||
classDescriptor: ClassDescriptorWithResolutionScopes,
|
classDescriptor: ClassDescriptorWithResolutionScopes,
|
||||||
nestedClassConstructors: Collection<ConstructorDescriptor>
|
nestedClassConstructors: Collection<FunctionDescriptor>
|
||||||
) {
|
) {
|
||||||
val functionsByName = MultiMap.create<Name, CallableMemberDescriptor>()
|
val functionsByName = MultiMap.create<Name, CallableMemberDescriptor>()
|
||||||
|
|
||||||
@@ -92,12 +92,7 @@ class OverloadResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (nestedConstructor in nestedClassConstructors) {
|
for (nestedConstructor in nestedClassConstructors) {
|
||||||
val name =
|
val name = nestedConstructor.containingDeclaration.name
|
||||||
if (nestedConstructor is TypeAliasConstructorDescriptor)
|
|
||||||
nestedConstructor.typeAliasDescriptor.name
|
|
||||||
else
|
|
||||||
nestedConstructor.containingDeclaration.name
|
|
||||||
|
|
||||||
functionsByName.putValue(name, nestedConstructor)
|
functionsByName.putValue(name, nestedConstructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ class CandidateResolver(
|
|||||||
val substitutedType = typeAliasParametersSubstitutor.substitute(typeAliasConstructorDescriptor.returnType, Variance.INVARIANT)!!
|
val substitutedType = typeAliasParametersSubstitutor.substitute(typeAliasConstructorDescriptor.returnType, Variance.INVARIANT)!!
|
||||||
val boundsSubstitutor = TypeSubstitutor.create(substitutedType)
|
val boundsSubstitutor = TypeSubstitutor.create(substitutedType)
|
||||||
|
|
||||||
val typeAliasDescriptor = typeAliasConstructorDescriptor.typeAliasDescriptor
|
val typeAliasDescriptor = typeAliasConstructorDescriptor.containingDeclaration
|
||||||
|
|
||||||
val unsubstitutedType = typeAliasDescriptor.expandedType
|
val unsubstitutedType = typeAliasDescriptor.expandedType
|
||||||
if (unsubstitutedType.isError) return
|
if (unsubstitutedType.isError) return
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.tower
|
package org.jetbrains.kotlin.resolve.calls.tower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -297,7 +298,7 @@ private fun getClassWithConstructors(classifier: ClassifierDescriptor?): ClassDe
|
|||||||
private val ClassDescriptor.canHaveCallableConstructors: Boolean
|
private val ClassDescriptor.canHaveCallableConstructors: Boolean
|
||||||
get() = !ErrorUtils.isError(this) && !kind.isSingleton
|
get() = !ErrorUtils.isError(this) && !kind.isSingleton
|
||||||
|
|
||||||
fun ClassifierDescriptor.getTypeAliasConstructors(): Collection<ConstructorDescriptor> {
|
fun ClassifierDescriptor.getTypeAliasConstructors(): Collection<TypeAliasConstructorDescriptor> {
|
||||||
if (this !is TypeAliasDescriptor) return emptyList()
|
if (this !is TypeAliasDescriptor) return emptyList()
|
||||||
|
|
||||||
val classDescriptor = this.classDescriptor ?: return emptyList()
|
val classDescriptor = this.classDescriptor ?: return emptyList()
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
typealias Exn = java.lang.Exception
|
typealias Exn = java.lang.Exception
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
throw <!NO_COMPANION_OBJECT!>Exn<!>
|
throw <!FUNCTION_CALL_EXPECTED!>Exn<!>
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.descriptors;
|
|||||||
import kotlin.collections.SetsKt;
|
import kotlin.collections.SetsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue;
|
||||||
@@ -317,13 +316,6 @@ public class Visibilities {
|
|||||||
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility.class);
|
parent = DescriptorUtils.getParentOfType(parent, DeclarationDescriptorWithVisibility.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (what instanceof TypeAliasConstructorDescriptor) {
|
|
||||||
DeclarationDescriptorWithVisibility invisibleMember =
|
|
||||||
findInvisibleMember(receiver, ((TypeAliasConstructorDescriptor) what).getTypeAliasDescriptor(), from);
|
|
||||||
|
|
||||||
if (invisibleMember != null) return invisibleMember;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+49
-17
@@ -20,27 +20,46 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
interface TypeAliasConstructorDescriptor : ConstructorDescriptor {
|
interface TypeAliasConstructorDescriptor : FunctionDescriptor {
|
||||||
val typeAliasDescriptor: TypeAliasDescriptor
|
|
||||||
val underlyingConstructorDescriptor: ConstructorDescriptor
|
val underlyingConstructorDescriptor: ConstructorDescriptor
|
||||||
|
|
||||||
|
override fun getContainingDeclaration(): TypeAliasDescriptor
|
||||||
|
|
||||||
|
override fun getReturnType(): KotlinType
|
||||||
|
|
||||||
|
override fun getOriginal(): TypeAliasConstructorDescriptor
|
||||||
|
|
||||||
|
override fun substitute(substitutor: TypeSubstitutor): TypeAliasConstructorDescriptor
|
||||||
|
|
||||||
|
override fun copy(
|
||||||
|
newOwner: DeclarationDescriptor,
|
||||||
|
modality: Modality,
|
||||||
|
visibility: Visibility,
|
||||||
|
kind: Kind,
|
||||||
|
copyOverrides: Boolean
|
||||||
|
): TypeAliasConstructorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeAliasConstructorDescriptorImpl private constructor(
|
class TypeAliasConstructorDescriptorImpl private constructor(
|
||||||
override val typeAliasDescriptor: TypeAliasDescriptor,
|
val typeAliasDescriptor: TypeAliasDescriptor,
|
||||||
override val underlyingConstructorDescriptor: ConstructorDescriptor,
|
override val underlyingConstructorDescriptor: ConstructorDescriptor,
|
||||||
containingDeclaration: ClassDescriptor,
|
|
||||||
original: TypeAliasConstructorDescriptor?,
|
original: TypeAliasConstructorDescriptor?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
primary: Boolean,
|
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
source: SourceElement
|
source: SourceElement
|
||||||
) : TypeAliasConstructorDescriptor,
|
) : TypeAliasConstructorDescriptor,
|
||||||
ConstructorDescriptorImpl(containingDeclaration, original, annotations,
|
FunctionDescriptorImpl(typeAliasDescriptor, original, annotations, Name.special("<init>"), kind, source)
|
||||||
primary, kind, source)
|
|
||||||
{
|
{
|
||||||
|
override fun getContainingDeclaration(): TypeAliasDescriptor =
|
||||||
|
typeAliasDescriptor
|
||||||
|
|
||||||
|
override fun getReturnType(): KotlinType =
|
||||||
|
super.getReturnType()!!
|
||||||
|
|
||||||
override fun getOriginal(): TypeAliasConstructorDescriptor =
|
override fun getOriginal(): TypeAliasConstructorDescriptor =
|
||||||
super.getOriginal() as TypeAliasConstructorDescriptor
|
super.getOriginal() as TypeAliasConstructorDescriptor
|
||||||
|
|
||||||
@@ -76,30 +95,43 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
|||||||
assert(newName == null) { "Renaming type alias constructor: $this" }
|
assert(newName == null) { "Renaming type alias constructor: $this" }
|
||||||
return TypeAliasConstructorDescriptorImpl(
|
return TypeAliasConstructorDescriptorImpl(
|
||||||
typeAliasDescriptor, underlyingConstructorDescriptor,
|
typeAliasDescriptor, underlyingConstructorDescriptor,
|
||||||
newOwner as ClassDescriptor,
|
|
||||||
this,
|
this,
|
||||||
annotations, isPrimary, Kind.DECLARATION, source)
|
annotations,
|
||||||
|
Kind.DECLARATION, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun create(
|
fun create(
|
||||||
typeAliasDescriptor: TypeAliasDescriptor,
|
typeAliasDescriptor: TypeAliasDescriptor,
|
||||||
underlyingConstructor: ConstructorDescriptor,
|
constructor: ConstructorDescriptor,
|
||||||
substitutor: TypeSubstitutor
|
substitutor: TypeSubstitutor
|
||||||
): TypeAliasConstructorDescriptor? = with(underlyingConstructor) {
|
): TypeAliasConstructorDescriptor? {
|
||||||
val typeAliasConstructor =
|
val typeAliasConstructor =
|
||||||
TypeAliasConstructorDescriptorImpl(typeAliasDescriptor, underlyingConstructor, containingDeclaration, null,
|
TypeAliasConstructorDescriptorImpl(typeAliasDescriptor, constructor, null, constructor.annotations,
|
||||||
annotations, isPrimary, kind, typeAliasDescriptor.source)
|
constructor.kind, typeAliasDescriptor.source)
|
||||||
|
|
||||||
val valueParameters =
|
val valueParameters =
|
||||||
FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, valueParameters, substitutor, false)
|
FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, substitutor, false)
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
typeAliasConstructor.initialize(valueParameters, visibility, typeAliasDescriptor.declaredTypeParameters)
|
val returnType = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||||
|
?: return null
|
||||||
|
|
||||||
typeAliasConstructor.returnType = substitutor.substitute(returnType, Variance.OUT_VARIANCE) ?: return null
|
val dispatchReceiverParameter =
|
||||||
|
if (constructor.containingDeclaration.isInner)
|
||||||
|
constructor.containingDeclaration.thisAsReceiverParameter
|
||||||
|
else
|
||||||
|
null
|
||||||
|
|
||||||
typeAliasConstructor
|
typeAliasConstructor.initialize(null,
|
||||||
|
dispatchReceiverParameter,
|
||||||
|
typeAliasDescriptor.declaredTypeParameters,
|
||||||
|
valueParameters,
|
||||||
|
returnType,
|
||||||
|
Modality.FINAL,
|
||||||
|
constructor.visibility)
|
||||||
|
|
||||||
|
return typeAliasConstructor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user