No variance elision in type alias substitution.

Add test with cyclic inheritance via type alias.
This commit is contained in:
Dmitry Petrov
2016-11-21 14:35:56 +03:00
parent 67fe28b8d8
commit e6fcf20cf2
10 changed files with 167 additions and 37 deletions
@@ -238,7 +238,10 @@ public class DescriptorResolver {
}
}
// If we have an abbreviated type (written with a type alias), it still can contain type projections in top-level arguments.
if (!type.isError() && SpecialTypesKt.getAbbreviatedType(type) != null && !hasProjectionsInWrittenArguments) {
// Only interface inheritance should be checked here.
// Corresponding check for classes is performed for type alias constructor calls in CandidateResolver.
if (TypeUtilsKt.isInterface(type) && TypeUtilsKt.containsTypeProjectionsInTopLevelArguments(type)) {
trace.report(EXPANDED_TYPE_CANNOT_BE_INHERITED.on(typeElement, type));
}
@@ -59,6 +59,8 @@ class TypeAliasExpander(
}
private fun SimpleType.combineAnnotations(annotations: Annotations): SimpleType {
if (isError) return this
val existingAnnotationTypes = this.annotations.getAllAnnotations().mapTo(hashSetOf<KotlinType>()) { it.annotation.type }
for (annotation in annotations) {
@@ -101,7 +103,8 @@ class TypeAliasExpander(
val argumentVariance = argument.projectionKind
val underlyingVariance = underlyingProjection.projectionKind
val argumentType = argument.type as? SimpleType ?: throw AssertionError("Non-simple type in type alias argument: $argument")
val argumentType = argument.type.unwrap() as? SimpleType ?:
throw AssertionError("Non-simple type in type alias argument: $argument")
val substitutionVariance =
when {
@@ -117,7 +120,7 @@ class TypeAliasExpander(
val parameterVariance = typeParameterDescriptor?.variance ?: Variance.INVARIANT
val resultingVariance =
when {
parameterVariance == substitutionVariance -> Variance.INVARIANT
parameterVariance == substitutionVariance -> substitutionVariance
parameterVariance == Variance.INVARIANT -> substitutionVariance
substitutionVariance == Variance.INVARIANT -> Variance.INVARIANT
else -> {