diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index a0e90e7dfe1..dd05f944457 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -11050,6 +11050,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); } + + @TestMetadata("reifiedParameterWithRecursiveBound.kt") + public void testReifiedParameterWithRecursiveBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation") diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt index 606fe30c04e..d4491b8c075 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt @@ -54,8 +54,8 @@ class VariableFixationFinder( enum class TypeVariableFixationReadiness { FORBIDDEN, WITHOUT_PROPER_ARGUMENT_CONSTRAINT, // proper constraint from arguments -- not from upper bound for type parameters - WITH_COMPLEX_DEPENDENCY_LOWER, // if type variable T has constraint with non fixed type variable inside (non-top-level): T <: Foo - WITH_COMPLEX_DEPENDENCY_UPPER, // Foo <: T + WITH_COMPLEX_DEPENDENCY_LOWER, // if type variable T has constraint with non fixed type variable inside (non-top-level): Foo <: T + WITH_COMPLEX_DEPENDENCY_UPPER, // T <: Foo WITH_TRIVIAL_OR_NON_PROPER_CONSTRAINTS, // proper trivial constraint from arguments, Nothing <: T RELATED_TO_ANY_OUTPUT_TYPE, READY_FOR_FIXATION, @@ -124,7 +124,10 @@ class VariableFixationFinder( private fun Context.hasDependencyToOtherTypeVariables(typeVariable: TypeConstructorMarker, kind: ConstraintKind): Boolean { for (constraint in notFixedTypeVariables[typeVariable]?.constraints ?: return false) { if (constraint.kind != kind || constraint.kind == ConstraintKind.EQUALITY) continue - if (constraint.type.lowerBoundIfFlexible().argumentsCount() != 0 && constraint.type.contains { notFixedTypeVariables.containsKey(it.typeConstructor()) }) { + if (constraint.type.lowerBoundIfFlexible().argumentsCount() != 0 + && constraint.type.contains { + it.typeConstructor() != typeVariable && notFixedTypeVariables.containsKey(it.typeConstructor()) + }) { return true } } diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.fir.kt new file mode 100644 index 00000000000..ec2982fe8a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.fir.kt @@ -0,0 +1,35 @@ +// Issue: KT-37621 +// !LANGUAGE: +NewInference + +class Inv +class In +class Out + +inline fun > invBound(): TB = TODO() +inline fun > inBound(): IB = TODO() +inline fun > outBound(): OB = TODO() + +inline fun > testInv(): T { + return try { + invBound() + } catch (ex: Exception) { + throw Exception() + } +} + +inline fun > testIn(): T { + return try { + inBound() + } catch (ex: Exception) { + throw Exception() + } +} + +// Unexpected behaviour +inline fun > testOut(): T { + return try { + outBound() + } catch (ex: Exception) { + throw Exception() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt new file mode 100644 index 00000000000..e385c67e256 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt @@ -0,0 +1,35 @@ +// Issue: KT-37621 +// !LANGUAGE: +NewInference + +class Inv +class In +class Out + +inline fun > invBound(): TB = TODO() +inline fun > inBound(): IB = TODO() +inline fun > outBound(): OB = TODO() + +inline fun > testInv(): T { + return try { + invBound() + } catch (ex: Exception) { + throw Exception() + } +} + +inline fun > testIn(): T { + return try { + inBound() + } catch (ex: Exception) { + throw Exception() + } +} + +// Unexpected behaviour +inline fun > testOut(): T { + return try { + outBound() + } catch (ex: Exception) { + throw Exception() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.txt b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.txt new file mode 100644 index 00000000000..ca288f50e87 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.txt @@ -0,0 +1,29 @@ +package + +public inline fun > inBound(): IB +public inline fun > invBound(): TB +public inline fun > outBound(): OB +public inline fun > testIn(): T +public inline fun > testInv(): T +public inline fun > testOut(): T + +public final class In { + public constructor In() + 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 Inv { + public constructor Inv() + 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 Out { + public constructor Out() + 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/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index edf5af8bfcd..71029936cd7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -11057,6 +11057,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); } + + @TestMetadata("reifiedParameterWithRecursiveBound.kt") + public void testReifiedParameterWithRecursiveBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 16d37d269ab..52ee095b111 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -11052,6 +11052,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing public void testPlatformNothingAsUsefulConstraint() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/platformNothingAsUsefulConstraint.kt"); } + + @TestMetadata("reifiedParameterWithRecursiveBound.kt") + public void testReifiedParameterWithRecursiveBound() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt"); + } } @TestMetadata("compiler/testData/diagnostics/tests/inference/publicApproximation")