Fix AssertionError in DescriptorResolver#checkBounds
#KT-9620 Fixed
This commit is contained in:
@@ -1152,33 +1152,33 @@ public class DescriptorResolver {
|
||||
List<TypeProjection> arguments = type.getArguments();
|
||||
assert parameters.size() == arguments.size();
|
||||
|
||||
List<KtTypeReference> jetTypeArguments = typeElement.getTypeArgumentsAsTypes();
|
||||
List<KtTypeReference> ktTypeArguments = typeElement.getTypeArgumentsAsTypes();
|
||||
|
||||
// A type reference from Kotlin code can yield a flexible type only if it's `ft<T1, T2>`, whose bounds should not be checked
|
||||
if (FlexibleTypesKt.isFlexible(type) && !DynamicTypesKt.isDynamic(type)) {
|
||||
assert jetTypeArguments.size() == 2
|
||||
assert ktTypeArguments.size() == 2
|
||||
: "Flexible type cannot be denoted in Kotlin otherwise than as ft<T1, T2>, but was: "
|
||||
+ PsiUtilsKt.getElementTextWithContext(typeReference);
|
||||
// it's really ft<Foo, Bar>
|
||||
FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type);
|
||||
checkBounds(jetTypeArguments.get(0), flexibleType.getLowerBound(), trace);
|
||||
checkBounds(jetTypeArguments.get(1), flexibleType.getUpperBound(), trace);
|
||||
checkBounds(ktTypeArguments.get(0), flexibleType.getLowerBound(), trace);
|
||||
checkBounds(ktTypeArguments.get(1), flexibleType.getUpperBound(), trace);
|
||||
return;
|
||||
}
|
||||
|
||||
assert jetTypeArguments.size() <= arguments.size() : typeElement.getText() + ": " + jetTypeArguments + " - " + arguments;
|
||||
// If the numbers of type arguments do not match, the error has been already reported in TypeResolver
|
||||
if (ktTypeArguments.size() != arguments.size()) return;
|
||||
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
|
||||
for (int i = 0; i < jetTypeArguments.size(); i++) {
|
||||
KtTypeReference jetTypeArgument = jetTypeArguments.get(i);
|
||||
|
||||
if (jetTypeArgument == null) continue;
|
||||
for (int i = 0; i < ktTypeArguments.size(); i++) {
|
||||
KtTypeReference ktTypeArgument = ktTypeArguments.get(i);
|
||||
if (ktTypeArgument == null) continue;
|
||||
|
||||
KotlinType typeArgument = arguments.get(i).getType();
|
||||
checkBounds(jetTypeArgument, typeArgument, trace);
|
||||
checkBounds(ktTypeArgument, typeArgument, trace);
|
||||
|
||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
||||
checkBounds(jetTypeArgument, typeArgument, typeParameterDescriptor, substitutor, trace);
|
||||
checkBounds(ktTypeArgument, typeArgument, typeParameterDescriptor, substitutor, trace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// KT-9620 AssertionError in checkBounds
|
||||
|
||||
interface E1<T : D<!TYPE_ARGUMENTS_NOT_ALLOWED!><String><!>, D>
|
||||
|
||||
interface A
|
||||
interface B
|
||||
interface D<X>
|
||||
interface E2<T : D<!TYPE_ARGUMENTS_NOT_ALLOWED!><A><!>, D<!SYNTAX!><<!><!SYNTAX!>B<!><!SYNTAX!>><!><!SYNTAX!>><!>
|
||||
|
||||
// KT-11354 AE from DescriptorResolver
|
||||
|
||||
open class L<E>()
|
||||
|
||||
class M<C> : L<C<!TYPE_ARGUMENTS_NOT_ALLOWED!><C><!>>()
|
||||
@@ -0,0 +1,45 @@
|
||||
package
|
||||
|
||||
public interface A {
|
||||
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 B {
|
||||
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 D</*0*/ X> {
|
||||
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 E1</*0*/ T : D, /*1*/ D> {
|
||||
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 E2</*0*/ T : D, /*1*/ D> {
|
||||
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 L</*0*/ E> {
|
||||
public constructor L</*0*/ E>()
|
||||
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 M</*0*/ C> : L<C> {
|
||||
public constructor M</*0*/ C>()
|
||||
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
|
||||
}
|
||||
@@ -14898,6 +14898,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9620.kt")
|
||||
public void testKt9620() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt9620.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9633.kt")
|
||||
public void testKt9633() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt9633.kt");
|
||||
|
||||
Reference in New Issue
Block a user