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;
}
}