From b87c2a15b5119a7a80ab869ca6eb5886cace60cc Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 3 Mar 2021 16:34:00 +0300 Subject: [PATCH] Don't stop constraints processing if all type variables have proper equality constraints Those type variable may have other constraints after incorporation into which, the constraint error may appear ^KT-42042 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../components/ConstraintInjector.kt | 11 ----------- compiler/testData/diagnostics/tests/Bounds.kt | 4 ++-- .../tests/generics/innerClasses/innerTP.kt | 2 +- .../manyConstraintsDueToFlexibleRawTypes.kt | 2 +- .../classTypeParameterInferredFromArgument.kt | 2 +- .../j+k/genericConstructor/innerClass.kt | 2 +- .../tests/typeParameters/kt42042.fir.kt | 11 +++++++++++ .../tests/typeParameters/kt42042.kt | 11 +++++++++++ .../tests/typeParameters/kt42042.txt | 19 +++++++++++++++++++ ...boundsViolationInDeepTypeAliasExpansion.kt | 2 +- .../boundsViolationInTypeAliasExpansion.kt | 2 +- .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 13 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/typeParameters/kt42042.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/kt42042.kt create mode 100644 compiler/testData/diagnostics/tests/typeParameters/kt42042.txt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 3b262b3bfb4..e4b96f629b0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -28773,6 +28773,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.kt"); } + @Test + @TestMetadata("kt42042.kt") + public void testKt42042() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/kt42042.kt"); + } + @Test @TestMetadata("kt42396.kt") public void testKt42396() throws Exception { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 61eca16a127..fd7d66d76f5 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -122,17 +122,6 @@ class ConstraintInjector( constraintIncorporator.incorporate(typeCheckerContext, typeVariable, constraintToIncorporate) } } - - val contextOps = c as? ConstraintSystemOperation - if (!typeCheckerContext.hasConstraintsToProcess() || - (contextOps != null && c.notFixedTypeVariables.all { typeVariable -> - typeVariable.value.constraints.any { constraint -> - constraint.kind == EQUALITY && contextOps.isProperType(constraint.type) - } - }) - ) { - break - } } } diff --git a/compiler/testData/diagnostics/tests/Bounds.kt b/compiler/testData/diagnostics/tests/Bounds.kt index d91a22dc5c3..1f0a3c601b9 100644 --- a/compiler/testData/diagnostics/tests/Bounds.kt +++ b/compiler/testData/diagnostics/tests/Bounds.kt @@ -7,12 +7,12 @@ package boundsWithSubstitutors class C : A() val a = B() - val a1 = B<Int>() + val a1 = B<Int>() class X() val b = X, C>>() - val b0 = XAny?>() + val b0 = XAny?>() val b1 = X, String>>() // FILE: b.kt diff --git a/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt index 1e47b515c93..96d0f0e7574 100644 --- a/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt +++ b/compiler/testData/diagnostics/tests/generics/innerClasses/innerTP.kt @@ -32,7 +32,7 @@ fun main() { checkSubtype.Inner<*>>(outer.Inner()) checkSubtype.Inner>(outer.bar()) - checkSubtype.Inner>(outer.Inner()) + checkSubtype.Inner>(outer.Inner()) outer.set(outer.bar()) outer.set(outer.Inner()) diff --git a/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.kt b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.kt index d19f12d2a13..163308f508e 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/manyConstraintsDueToFlexibleRawTypes.kt @@ -28,5 +28,5 @@ abstract class MySettingsListener {} fun test() { val a = MySettings.getSettings() a.getLinkedProjectsSettings() - a.linkedProjectsSettings + a.linkedProjectsSettings } diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt index 448249692cd..151342d0422 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/classTypeParameterInferredFromArgument.kt @@ -12,6 +12,6 @@ fun test(x: List, y: List) { A("", x) checkType { _>() } A("", y) checkType { _>() } - A("", x) + A("", x) A("", y) } diff --git a/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt index fd9bb366698..b63c804e0cc 100644 --- a/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt +++ b/compiler/testData/diagnostics/tests/j+k/genericConstructor/innerClass.kt @@ -14,5 +14,5 @@ fun test(x: List, y: List) { Outer().Inner("", y, 1) checkType { _.Inner>() } Outer().Inner("", x, 1) checkType { _.Inner>() } - Outer().Inner("", x, 1) + Outer().Inner("", x, 1) } diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt42042.fir.kt b/compiler/testData/diagnostics/tests/typeParameters/kt42042.fir.kt new file mode 100644 index 00000000000..cc6fee6ab05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/kt42042.fir.kt @@ -0,0 +1,11 @@ +sealed class Subtype { + abstract fun cast(value: A1): B1 + class Trivial : Subtype() { + override fun cast(value: A2): B2 = value + } +} + +fun unsafeCast(value: A): B { + val proof: Subtype = Subtype.Trivial() + return proof.cast(value) +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt42042.kt b/compiler/testData/diagnostics/tests/typeParameters/kt42042.kt new file mode 100644 index 00000000000..e127db69652 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/kt42042.kt @@ -0,0 +1,11 @@ +sealed class Subtype { + abstract fun cast(value: A1): B1 + class Trivial : Subtype() { + override fun cast(value: A2): B2 = value + } +} + +fun unsafeCast(value: A): B { + val proof: Subtype = Subtype.Trivial() + return proof.cast(value) +} diff --git a/compiler/testData/diagnostics/tests/typeParameters/kt42042.txt b/compiler/testData/diagnostics/tests/typeParameters/kt42042.txt new file mode 100644 index 00000000000..1472e3562e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typeParameters/kt42042.txt @@ -0,0 +1,19 @@ +package + +public fun unsafeCast(/*0*/ value: A): B + +public sealed class Subtype { + protected constructor Subtype() + public abstract fun cast(/*0*/ value: A1): B1 + 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 Trivial : Subtype { + public constructor Trivial() + public open override /*1*/ fun cast(/*0*/ value: A2): B2 + 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 + } +} diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt index fcf532a4be2..55aee58d27e 100644 --- a/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInDeepTypeAliasExpansion.kt @@ -14,4 +14,4 @@ fun test4(x: TC2>() val test6 = TC2>() val test7 = TC2>() -val test8 = TC2List>() +val test8 = TC2List>() diff --git a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt index 66998fd9bfe..98590c1db64 100644 --- a/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt +++ b/compiler/testData/diagnostics/tests/typealias/boundsViolationInTypeAliasExpansion.kt @@ -29,4 +29,4 @@ fun test12(x: TCList>) {} val test13 = TC>() val test14 = TC>() val test15 = TC>() -val test16 = TCList>() +val test16 = TCList>() diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 519a7a1a6cf..5077b3dd679 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -28869,6 +28869,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/typeParameters/implicitNothingOnDelegates.kt"); } + @Test + @TestMetadata("kt42042.kt") + public void testKt42042() throws Exception { + runTest("compiler/testData/diagnostics/tests/typeParameters/kt42042.kt"); + } + @Test @TestMetadata("kt42396.kt") public void testKt42396() throws Exception {