diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt new file mode 100644 index 00000000000..b8ad6688ae5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.kt @@ -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 + +class B(foo: A) { + fun test1(a: A) { + B(a) + val b: B = B(a) + // crash here + } +} + +class C + +class D(foo: C) { + fun test(a: C) { + val d: D = D(a) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt6320.txt b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.txt new file mode 100644 index 00000000000..9b23f72ca4b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt6320.txt @@ -0,0 +1,31 @@ +package + +internal final class A { + public constructor 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 +} + +internal final class B { + public constructor B(/*0*/ foo: 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 + internal final fun test1(/*0*/ a: A): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class C { + public constructor 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 +} + +internal final class D { + public constructor D(/*0*/ foo: 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 + internal final fun test(/*0*/ a: C): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 5e620012ced..689158dee78 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5151,6 +5151,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { 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") public void testNotNullConstraintOnNullableType() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt"); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.kt b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.kt index 45e2794a81c..b32759e918b 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.kt +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.kt @@ -304,13 +304,9 @@ public class ConstraintSystemImpl : ConstraintSystem { } fun simplifyConstraint(subType: JetType, superType: JetType) { - // can be equal for the recursive invocations: - // fun foo(i: Int) : T { ... return foo(i); } => T <: T - if (isMyTypeVariable(subType) && isMyTypeVariable(superType) && JetTypeChecker.DEFAULT.equalTypes(subType, superType)) return - - assert(!isMyTypeVariable(subType) || !isMyTypeVariable(superType)) { - "The constraint shouldn't contain different type variables on both sides: " + subType + " <: " + superType - } + // can be equal for the recursive invocations: fun 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)) return if (isMyTypeVariable(subType)) { val boundKind = if (constraintKind == SUB_TYPE) UPPER_BOUND else EXACT_BOUND