KT-6320 AssertionError in ConstraintSystem(The constraint shouldn't contain different type variables on both sides: Y <: X)
#KT-6320 Fixed
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
// AssertionError in ConstraintSystem(The constraint shouldn't contain different type variables on both sides: Y <: X)
|
||||||
|
|
||||||
|
class A<X, Y : X>
|
||||||
|
|
||||||
|
class B<X, Y : X>(foo: A<X, Y>) {
|
||||||
|
fun test1(a: A<X, Y>) {
|
||||||
|
B(a)
|
||||||
|
val b: B<X, Y> = B(a)
|
||||||
|
// crash here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C<X, Z, Y : X>
|
||||||
|
|
||||||
|
class D<X, Z, Y : X>(foo: C<X, Z, Y>) {
|
||||||
|
fun test(a: C<Y, Y, Y>) {
|
||||||
|
val d: D<X, Y, Y> = <!TYPE_MISMATCH!>D(a)<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal final class A</*0*/ X, /*1*/ Y : X> {
|
||||||
|
public constructor A</*0*/ X, /*1*/ Y : 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
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class B</*0*/ X, /*1*/ Y : X> {
|
||||||
|
public constructor B</*0*/ X, /*1*/ Y : X>(/*0*/ foo: A<X, Y>)
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
internal final fun test1(/*0*/ a: A<X, Y>): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class C</*0*/ X, /*1*/ Z, /*2*/ Y : X> {
|
||||||
|
public constructor C</*0*/ X, /*1*/ Z, /*2*/ Y : 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
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class D</*0*/ X, /*1*/ Z, /*2*/ Y : X> {
|
||||||
|
public constructor D</*0*/ X, /*1*/ Z, /*2*/ Y : X>(/*0*/ foo: C<X, Z, Y>)
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
internal final fun test(/*0*/ a: C<Y, Y, Y>): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -5151,6 +5151,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt6320.kt")
|
||||||
|
public void testKt6320() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("notNullConstraintOnNullableType.kt")
|
@TestMetadata("notNullConstraintOnNullableType.kt")
|
||||||
public void testNotNullConstraintOnNullableType() throws Exception {
|
public void testNotNullConstraintOnNullableType() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt");
|
||||||
|
|||||||
+3
-7
@@ -304,13 +304,9 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun simplifyConstraint(subType: JetType, superType: JetType) {
|
fun simplifyConstraint(subType: JetType, superType: JetType) {
|
||||||
// can be equal for the recursive invocations:
|
// can be equal for the recursive invocations: fun <T> foo(i: Int) : T { ... return foo(i); } => T <: T
|
||||||
// fun <T> foo(i: Int) : T { ... return foo(i); } => T <: T
|
// the right processing of constraints connecting type variables is not supported yet
|
||||||
if (isMyTypeVariable(subType) && isMyTypeVariable(superType) && JetTypeChecker.DEFAULT.equalTypes(subType, superType)) return
|
if (isMyTypeVariable(subType) && isMyTypeVariable(superType)) return
|
||||||
|
|
||||||
assert(!isMyTypeVariable(subType) || !isMyTypeVariable(superType)) {
|
|
||||||
"The constraint shouldn't contain different type variables on both sides: " + subType + " <: " + superType
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMyTypeVariable(subType)) {
|
if (isMyTypeVariable(subType)) {
|
||||||
val boundKind = if (constraintKind == SUB_TYPE) UPPER_BOUND else EXACT_BOUND
|
val boundKind = if (constraintKind == SUB_TYPE) UPPER_BOUND else EXACT_BOUND
|
||||||
|
|||||||
Reference in New Issue
Block a user