KT-14274: resolve type alias constructors calls in supertypes list as type alias constructors.

Support @Deprecated for type aliases, including type alias constructors.
This commit is contained in:
Dmitry Petrov
2016-10-10 18:21:19 +03:00
parent bee0e783f8
commit 8d634f6003
25 changed files with 285 additions and 43 deletions
@@ -1639,7 +1639,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
assert primaryConstructor != null : "There should be primary constructor for object literal";
ResolvedCall<ClassConstructorDescriptor> superCall = getDelegationConstructorCall(bindingContext, primaryConstructor);
ResolvedCall<ConstructorDescriptor> superCall = getDelegationConstructorCall(bindingContext, primaryConstructor);
if (superCall != null) {
// For an anonymous object, we should also generate all non-default arguments that it captures for its super call
ConstructorDescriptor superConstructor = superCall.getResultingDescriptor();
@@ -1049,10 +1049,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
markLineNumberForConstructor(constructorDescriptor, constructor, codegen);
ResolvedCall<ClassConstructorDescriptor> constructorDelegationCall =
ResolvedCall<ConstructorDescriptor> constructorDelegationCall =
getDelegationConstructorCall(bindingContext, constructorDescriptor);
ConstructorDescriptor delegateConstructor = constructorDelegationCall == null ? null :
constructorDelegationCall.getResultingDescriptor();
constructorDelegationCall.getResultingDescriptor();
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor, constructorDelegationCall);
if (!isSameClassConstructor(delegateConstructor)) {
@@ -1383,7 +1383,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@NotNull InstructionAdapter iv,
@NotNull ExpressionCodegen codegen,
@NotNull ClassConstructorDescriptor constructorDescriptor,
@Nullable ResolvedCall<ClassConstructorDescriptor> delegationConstructorCall
@Nullable ResolvedCall<ConstructorDescriptor> delegationConstructorCall
) {
if (delegationConstructorCall == null) {
genSimpleSuperCall(iv);
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.LocalVariableAccessorDescriptor;
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
import org.jetbrains.kotlin.fileClasses.FileClasses;
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
@@ -934,6 +935,9 @@ public class KotlinTypeMapper {
if (f instanceof FunctionImportedFromObject) {
return mapSignature(((FunctionImportedFromObject) f).getCallableFromObject(), kind, skipGenericSignature);
}
else if (f instanceof TypeAliasConstructorDescriptor) {
return mapSignature(((TypeAliasConstructorDescriptor) f).getUnderlyingConstructorDescriptor(), kind, valueParameters, skipGenericSignature);
}
checkOwnerCompatibility(f);
@@ -1272,7 +1276,7 @@ public class KotlinTypeMapper {
// We may generate a slightly wrong signature for a local class / anonymous object in light classes mode but we don't care,
// because such classes are not accessible from the outside world
if (classBuilderMode.generateBodies) {
ResolvedCall<ClassConstructorDescriptor> superCall = findFirstDelegatingSuperCall(descriptor);
ResolvedCall<ConstructorDescriptor> superCall = findFirstDelegatingSuperCall(descriptor);
if (superCall == null) return;
writeSuperConstructorCallParameters(sw, descriptor, superCall, captureThis != null);
}
@@ -1281,7 +1285,7 @@ public class KotlinTypeMapper {
private void writeSuperConstructorCallParameters(
@NotNull JvmSignatureWriter sw,
@NotNull ClassConstructorDescriptor descriptor,
@NotNull ResolvedCall<ClassConstructorDescriptor> superCall,
@NotNull ResolvedCall<ConstructorDescriptor> superCall,
boolean hasOuter
) {
ConstructorDescriptor superDescriptor = SamCodegenUtil.resolveSamAdapter(superCall.getResultingDescriptor());
@@ -1320,13 +1324,13 @@ public class KotlinTypeMapper {
}
@Nullable
private ResolvedCall<ClassConstructorDescriptor> findFirstDelegatingSuperCall(@NotNull ClassConstructorDescriptor descriptor) {
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
private ResolvedCall<ConstructorDescriptor> findFirstDelegatingSuperCall(@NotNull ConstructorDescriptor descriptor) {
ClassifierDescriptorWithTypeParameters constructorOwner = descriptor.getContainingDeclaration();
while (true) {
ResolvedCall<ClassConstructorDescriptor> next = getDelegationConstructorCall(bindingContext, descriptor);
ResolvedCall<ConstructorDescriptor> next = getDelegationConstructorCall(bindingContext, descriptor);
if (next == null) return null;
descriptor = next.getResultingDescriptor();
if (descriptor.getContainingDeclaration() != classDescriptor) return next;
if (descriptor.getContainingDeclaration() != constructorOwner) return next;
}
}
@@ -222,7 +222,7 @@ public interface BindingContext {
*/
WritableSlice<PsiElement, SimpleFunctionDescriptor> FUNCTION = Slices.createSimpleSlice();
WritableSlice<PsiElement, ConstructorDescriptor> CONSTRUCTOR = Slices.createSimpleSlice();
WritableSlice<ConstructorDescriptor, ResolvedCall<ClassConstructorDescriptor>> CONSTRUCTOR_RESOLVED_DELEGATION_CALL =
WritableSlice<ConstructorDescriptor, ResolvedCall<ConstructorDescriptor>> CONSTRUCTOR_RESOLVED_DELEGATION_CALL =
Slices.createSimpleSlice();
WritableSlice<PsiElement, VariableDescriptor> VARIABLE = Slices.createSimpleSlice();
WritableSlice<KtParameter, VariableDescriptor> VALUE_PARAMETER = Slices.createSimpleSlice();
@@ -222,7 +222,7 @@ public class BindingContextUtils {
}
@Nullable
public static ResolvedCall<ClassConstructorDescriptor> getDelegationConstructorCall(
public static ResolvedCall<ConstructorDescriptor> getDelegationConstructorCall(
@NotNull BindingContext bindingContext,
@NotNull ConstructorDescriptor constructorDescriptor
) {
@@ -231,7 +231,7 @@ public class BodyResolver {
@Nullable
private ConstructorDescriptor getDelegatedConstructor(@NotNull ConstructorDescriptor constructor) {
ResolvedCall<ClassConstructorDescriptor> call = trace.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor);
ResolvedCall<ConstructorDescriptor> call = trace.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor);
return call == null || !call.getStatus().isSuccess() ? null : call.getResultingDescriptor().getOriginal();
}
@@ -430,7 +430,7 @@ public class BodyResolver {
@NotNull ResolvedCall<?> call
) {
//noinspection unchecked
trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ClassConstructorDescriptor>) call);
trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ConstructorDescriptor>) call);
}
private void checkSupertypeList(
@@ -307,7 +307,7 @@ public class CallResolver {
return resolveCallForInvoke(context.replaceCall(call), tracingForInvoke);
}
private OverloadResolutionResults<ClassConstructorDescriptor> resolveCallForConstructor(
private OverloadResolutionResults<ConstructorDescriptor> resolveCallForConstructor(
@NotNull BasicCallResolutionContext context,
@NotNull KtConstructorCalleeExpression expression
) {
@@ -340,17 +340,17 @@ public class CallResolver {
return checkArgumentTypesAndFail(context);
}
Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
prepareCandidatesAndContextForConstructorCall(constructedType, context);
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
context = candidatesAndContext.getSecond();
return computeTasksFromCandidatesAndResolvedCall(context, functionReference, candidates);
}
@Nullable
public OverloadResolutionResults<ClassConstructorDescriptor> resolveConstructorDelegationCall(
public OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall(
@NotNull BindingTrace trace, @NotNull LexicalScope scope, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ClassConstructorDescriptor constructorDescriptor,
@NotNull KtConstructorDelegationCall call
@@ -380,7 +380,7 @@ public class CallResolver {
}
@NotNull
private OverloadResolutionResults<ClassConstructorDescriptor> resolveConstructorDelegationCall(
private OverloadResolutionResults<ConstructorDescriptor> resolveConstructorDelegationCall(
@NotNull BasicCallResolutionContext context,
@NotNull KtConstructorDelegationCall call,
@NotNull KtConstructorDelegationReferenceExpression calleeExpression,
@@ -420,9 +420,9 @@ public class CallResolver {
calleeConstructor.getContainingDeclaration().getDefaultType() :
DescriptorUtils.getSuperClassType(currentClassDescriptor);
Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> candidatesAndContext =
prepareCandidatesAndContextForConstructorCall(superType, context);
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates = candidatesAndContext.getFirst();
context = candidatesAndContext.getSecond();
TracingStrategy tracing = call.isImplicit() ?
@@ -441,17 +441,15 @@ public class CallResolver {
}
@NotNull
private static Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
private static Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext> prepareCandidatesAndContextForConstructorCall(
@NotNull KotlinType superType,
@NotNull BasicCallResolutionContext context
) {
if (!(superType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
return new Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext>(
Collections.<ResolutionCandidate<ClassConstructorDescriptor>>emptyList(), context);
return new Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext>(
Collections.<ResolutionCandidate<ConstructorDescriptor>>emptyList(), context);
}
ClassDescriptor superClass = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
// If any constructor has type parameter (currently it only can be true for ones from Java), try to infer arguments for them
// Otherwise use NO_EXPECTED_TYPE and knownTypeParametersSubstitutor
boolean anyConstructorHasDeclaredTypeParameters =
@@ -462,10 +460,10 @@ public class CallResolver {
context = context.replaceExpectedType(superType);
}
Collection<ResolutionCandidate<ClassConstructorDescriptor>> candidates =
CallResolverUtilKt.createResolutionCandidatesForConstructors(context.scope, context.call, superClass, knownTypeParametersSubstitutor);
Collection<ResolutionCandidate<ConstructorDescriptor>> candidates =
CallResolverUtilKt.createResolutionCandidatesForConstructors(context.scope, context.call, superType, knownTypeParametersSubstitutor);
return new Pair<Collection<ResolutionCandidate<ClassConstructorDescriptor>>, BasicCallResolutionContext>(candidates, context);
return new Pair<Collection<ResolutionCandidate<ConstructorDescriptor>>, BasicCallResolutionContext>(candidates, context);
}
private static boolean anyConstructorHasDeclaredTypeParameters(@Nullable ClassifierDescriptor classDescriptor) {
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.coroutines.getExpectedTypeForCoroutineControllerHandleResult
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptorImpl
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
@@ -200,9 +202,18 @@ fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argu
fun createResolutionCandidatesForConstructors(
lexicalScope: LexicalScope,
call: Call,
classWithConstructors: ClassDescriptor,
typeWithConstructors: KotlinType,
knownSubstitutor: TypeSubstitutor? = null
): Collection<ResolutionCandidate<ClassConstructorDescriptor>> {
): Collection<ResolutionCandidate<ConstructorDescriptor>> {
val classWithConstructors = typeWithConstructors.constructor.declarationDescriptor as ClassDescriptor
val unwrappedType = typeWithConstructors.unwrap()
val typeAliasDescriptor =
if (unwrappedType is AbbreviatedType)
unwrappedType.abbreviation.constructor.declarationDescriptor as? TypeAliasDescriptor
else
null
val constructors = classWithConstructors.constructors
if (constructors.isEmpty()) return emptyList()
@@ -212,7 +223,7 @@ fun createResolutionCandidatesForConstructors(
if (classWithConstructors.isInner) {
val outerClassType = (classWithConstructors.containingDeclaration as? ClassDescriptor)?.defaultType ?: return emptyList()
val substitutedOuterClassType = knownSubstitutor?.let { it.substitute(outerClassType, Variance.INVARIANT) } ?: outerClassType
val substitutedOuterClassType = knownSubstitutor?.substitute(outerClassType, Variance.INVARIANT) ?: outerClassType
val receiver = lexicalScope.getImplicitReceiversHierarchy().firstOrNull {
KotlinTypeChecker.DEFAULT.isSubtypeOf(it.type, substitutedOuterClassType)
@@ -226,9 +237,22 @@ fun createResolutionCandidatesForConstructors(
dispatchReceiver = null
}
return constructors.map { ResolutionCandidate.create(call, it, dispatchReceiver, receiverKind, knownSubstitutor) }
return constructors.map {
val constructorDescriptor = it.getConstructorDescriptorForResolution(knownSubstitutor, typeAliasDescriptor)
ResolutionCandidate.create(call, constructorDescriptor, dispatchReceiver, receiverKind, knownSubstitutor)
}
}
private fun ClassConstructorDescriptor.getConstructorDescriptorForResolution(
knownSubstitutor: TypeSubstitutor?,
typeAliasDescriptor: TypeAliasDescriptor?
): ConstructorDescriptor =
if (typeAliasDescriptor != null)
TypeAliasConstructorDescriptorImpl.create(typeAliasDescriptor, this, knownSubstitutor ?: TypeSubstitutor.EMPTY)
?: throw AssertionError("Failed to create type alias constructor with substitutor: $knownSubstitutor")
else
this
fun KtLambdaExpression.getCorrespondingParameterForFunctionArgument(
bindingContext: BindingContext
): ValueParameterDescriptor? {
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression
@@ -32,7 +33,13 @@ object ProtectedConstructorCallChecker : CallChecker {
val constructorOwner = descriptor.containingDeclaration.original
val scopeOwner = context.scope.ownerDescriptor
if (descriptor.visibility.normalize() != Visibilities.PROTECTED) return
val actualConstructor =
if (descriptor is TypeAliasConstructorDescriptor)
descriptor.underlyingConstructorDescriptor
else
descriptor
if (actualConstructor.visibility.normalize() != Visibilities.PROTECTED) return
// Error already reported
if (!Visibilities.isVisibleWithAnyReceiver(descriptor, scopeOwner)) return
@@ -52,7 +59,7 @@ object ProtectedConstructorCallChecker : CallChecker {
// And without ProtectedConstructorCallChecker such calls would be allowed only because they are performed within subclass
// of constructor owner
@Suppress("DEPRECATION")
if (Visibilities.findInvisibleMember(Visibilities.FALSE_IF_PROTECTED, descriptor, scopeOwner) == descriptor) {
if (Visibilities.findInvisibleMember(Visibilities.FALSE_IF_PROTECTED, descriptor, scopeOwner) == actualConstructor) {
context.trace.report(Errors.PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL.on(reportOn, descriptor))
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.FqName
@@ -137,6 +138,11 @@ private fun DeclarationDescriptor.getDeprecationByAnnotation(): DeprecatedByAnno
val classAnnotation = classDescriptor.getDeclaredDeprecatedAnnotation()
if (classAnnotation != null)
return DeprecatedByAnnotation(classAnnotation, classDescriptor)
if (this is TypeAliasConstructorDescriptor) {
val underlyingConstructorDeprecation = underlyingConstructorDescriptor.getDeprecationByAnnotation()
if (underlyingConstructorDeprecation != null)
return underlyingConstructorDeprecation
}
}
is PropertyAccessorDescriptor -> {
val propertyDescriptor = correspondingProperty
@@ -0,0 +1,10 @@
open class Cell<T>(val value: T)
typealias CT<T> = Cell<T>
typealias CStr = Cell<String>
class C1 : CT<String>("O")
class C2 : CStr("K")
fun box(): String =
C1().value + C2().value
@@ -0,0 +1,14 @@
@Deprecated("Deprecated class")
open class DeprecatedClass
open class WithDeprecatedCtor(val x: Int) {
@Deprecated("Deprecated constructor")
constructor() : this(0)
}
typealias DeprecatedClassAlias = <!DEPRECATION!>DeprecatedClass<!>
typealias WithDeprecatedCtorAlias = WithDeprecatedCtor
class Test1 : <!DEPRECATION!>DeprecatedClassAlias<!>()
class Test2 : <!DEPRECATION!>WithDeprecatedCtorAlias<!>()
@@ -0,0 +1,34 @@
package
@kotlin.Deprecated(message = "Deprecated class") public open class DeprecatedClass {
public constructor DeprecatedClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test1 : DeprecatedClassAlias /* = DeprecatedClass */ {
public constructor Test1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test2 : WithDeprecatedCtorAlias /* = WithDeprecatedCtor */ {
public constructor Test2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class WithDeprecatedCtor {
@kotlin.Deprecated(message = "Deprecated constructor") public constructor WithDeprecatedCtor()
public constructor WithDeprecatedCtor(/*0*/ x: kotlin.Int)
public final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public typealias DeprecatedClassAlias = DeprecatedClass
public typealias WithDeprecatedCtorAlias = WithDeprecatedCtor
@@ -0,0 +1,24 @@
open class Base {
companion object
}
interface IFoo
open class CG<T>
interface IG<T>
@Deprecated("Obsolete")
typealias Obsolete = Base
@Deprecated("Obsolete")
typealias IObsolete = IFoo
fun test1(x: <!DEPRECATION!>Obsolete<!>) = x
fun test1a(x: List<<!DEPRECATION!>Obsolete<!>>) = x
val test2 = <!DEPRECATION!>Obsolete<!>()
val test3 = <!DEPRECATION!>Obsolete<!>
class Test4: <!DEPRECATION!>Obsolete<!>()
class Test4a: <!DEPRECATION!>IObsolete<!>
class Test4b: IG<<!DEPRECATION!>Obsolete<!>>
class Test4c: CG<<!DEPRECATION!>Obsolete<!>>()
@@ -0,0 +1,69 @@
package
public val test2: Base
public val test3: Base.Companion
public fun test1(/*0*/ x: Obsolete /* = Base */): Obsolete /* = Base */
public fun test1a(/*0*/ x: kotlin.collections.List<Obsolete /* = Base */>): kotlin.collections.List<Obsolete /* = Base */>
public open class Base {
public constructor Base()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public open class CG</*0*/ T> {
public constructor CG</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface IFoo {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface IG</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test4 : Obsolete /* = Base */ {
public constructor Test4()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test4a : IObsolete /* = IFoo */ {
public constructor Test4a()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test4b : IG<Obsolete /* = Base */> {
public constructor Test4b()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Test4c : CG<Obsolete /* = Base */> {
public constructor Test4c()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@kotlin.Deprecated(message = "Obsolete") public typealias IObsolete = IFoo
@kotlin.Deprecated(message = "Obsolete") public typealias Obsolete = Base
@@ -19,7 +19,7 @@ val test3a = MyClass(1.0)
class MyDerived : MyClass(1.0) {
val test4 = <!NONE_APPLICABLE!>MyAlias<!>(1)
val test4a = <!NONE_APPLICABLE!>MyClass<!>(1)
val test5 = <!NONE_APPLICABLE!>MyAlias<!>("")
val test5 = <!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>MyAlias<!>("")
val test5a = <!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>MyClass<!>("")
val test6 = MyAlias(1.0)
val test6a = MyClass(1.0)
@@ -21,7 +21,7 @@ public final class MyDerived : MyClass {
public constructor MyDerived()
public final val test4: [ERROR : Type for MyAlias(1)]
public final val test4a: [ERROR : Type for MyClass(1)]
public final val test5: [ERROR : Type for MyAlias("")]
public final val test5: MyClass
public final val test5a: MyClass
public final val test6: MyClass
public final val test6a: MyClass
@@ -6048,6 +6048,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("typealiasConstructor.kt")
public void testTypealiasConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/typealiasConstructor.kt");
doTest(fileName);
}
@TestMetadata("typealiasUsage.kt")
public void testTypealiasUsage() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/typealiasUsage.kt");
doTest(fileName);
}
@TestMetadata("unusedImport.kt")
public void testUnusedImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/unusedImport.kt");
@@ -15952,6 +15952,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("typeAliasConstructorInSuperCall.kt")
public void testTypeAliasConstructorInSuperCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasConstructorInSuperCall.kt");
doTest(fileName);
}
@TestMetadata("typeAliasObject.kt")
public void testTypeAliasObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
@@ -111,17 +111,18 @@ class TypeAliasConstructorDescriptorImpl private constructor(
fun create(
typeAliasDescriptor: TypeAliasDescriptor,
constructor: ClassConstructorDescriptor,
substitutor: TypeSubstitutor
substitutor: TypeSubstitutor?
): TypeAliasConstructorDescriptor? {
val actualSubstitutor = substitutor ?: TypeSubstitutor.EMPTY
val typeAliasConstructor =
TypeAliasConstructorDescriptorImpl(typeAliasDescriptor, constructor, null, constructor.annotations,
constructor.kind, typeAliasDescriptor.source)
val valueParameters =
FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, substitutor, false)
?: return null
val valueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, actualSubstitutor, false)
?: return null
val returnType = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
val returnType = actualSubstitutor.substitute(constructor.returnType, Variance.INVARIANT)
?: return null
val containingDeclaration = constructor.containingDeclaration
@@ -137,10 +138,12 @@ class TypeAliasConstructorDescriptorImpl private constructor(
valueParameters,
returnType,
Modality.FINAL,
constructor.visibility)
typeAliasDescriptor.visibility)
return typeAliasConstructor
}
}
}
@@ -0,0 +1,9 @@
package test
open class C
typealias CA = C
class D : <caret>CA()
// REF: (test).CA
@@ -395,6 +395,12 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
doTest(fileName);
}
@TestMetadata("TypeAliasAsSupertypeConstructor.kt")
public void testTypeAliasAsSupertypeConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/references/TypeAliasAsSupertypeConstructor.kt");
doTest(fileName);
}
@TestMetadata("TypeAliasRHS.kt")
public void testTypeAliasRHS() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/references/TypeAliasRHS.kt");
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.js.naming
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -89,6 +90,9 @@ class NameSuggestion {
// It's a special case when an object has `invoke` operator defined, in this case we simply generate object itself
is FakeCallableDescriptorForObject -> return suggest(descriptor.getReferencedObject())
// For type alias constructor descriptors we generate references to underlying constructors
is TypeAliasConstructorDescriptor -> return suggest(descriptor.underlyingConstructorDescriptor)
// For primary constructors and constructors of native classes we generate references to containing classes
is ConstructorDescriptor -> {
if (descriptor.isPrimary || isNativeObject(descriptor)) {
@@ -71,6 +71,12 @@ public class TypeAliasesTestsGenerated extends AbstractTypeAliasesTests {
doTest(fileName);
}
@TestMetadata("typeAliasConstructorInSuperCall.kt")
public void testTypeAliasConstructorInSuperCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasConstructorInSuperCall.kt");
doTest(fileName);
}
@TestMetadata("typeAliasObject.kt")
public void testTypeAliasObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
import org.jetbrains.kotlin.js.config.JsConfig;
import org.jetbrains.kotlin.js.translate.intrinsic.Intrinsics;
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
@@ -463,6 +464,11 @@ public class TranslationContext {
@Nullable
public List<DeclarationDescriptor> getClassOrConstructorClosure(@NotNull MemberDescriptor classOrConstructor) {
if (classOrConstructor instanceof TypeAliasConstructorDescriptor) {
ClassConstructorDescriptor constructorDescriptor = ((TypeAliasConstructorDescriptor) classOrConstructor).getUnderlyingConstructorDescriptor();
return getClassOrConstructorClosure(constructorDescriptor);
}
List<DeclarationDescriptor> result = staticContext.getClassOrConstructorClosure(classOrConstructor);
if (result == null &&
classOrConstructor instanceof ConstructorDescriptor &&