[NI] Filter out type variable from its dependencies
Don't take into account complex variable dependency on itself when determining fixation status. ^KT-37621 Fixed
This commit is contained in:
+5
@@ -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")
|
||||
|
||||
+6
-3
@@ -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<S>
|
||||
WITH_COMPLEX_DEPENDENCY_UPPER, // Foo<S> <: T
|
||||
WITH_COMPLEX_DEPENDENCY_LOWER, // if type variable T has constraint with non fixed type variable inside (non-top-level): Foo<S> <: T
|
||||
WITH_COMPLEX_DEPENDENCY_UPPER, // T <: Foo<S>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
// Issue: KT-37621
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Inv<T>
|
||||
class In<in I>
|
||||
class Out<out O>
|
||||
|
||||
inline fun <reified TB : Inv<TB>> invBound(): TB = TODO()
|
||||
inline fun <reified IB : In<IB>> inBound(): IB = TODO()
|
||||
inline fun <reified OB : Out<OB>> outBound(): OB = TODO()
|
||||
|
||||
inline fun <reified T : Inv<T>> testInv(): T {
|
||||
return try {
|
||||
invBound()
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : In<T>> testIn(): T {
|
||||
return try {
|
||||
inBound()
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
// Unexpected behaviour
|
||||
inline fun <reified T : Out<T>> testOut(): T {
|
||||
return try {
|
||||
outBound()
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
// Issue: KT-37621
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Inv<T>
|
||||
class In<in I>
|
||||
class Out<out O>
|
||||
|
||||
inline fun <reified TB : Inv<TB>> invBound(): TB = TODO()
|
||||
inline fun <reified IB : In<IB>> inBound(): IB = TODO()
|
||||
inline fun <reified OB : Out<OB>> outBound(): OB = TODO()
|
||||
|
||||
inline fun <reified T : Inv<T>> testInv(): T {
|
||||
return try {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>invBound()<!>
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : In<T>> testIn(): T {
|
||||
return try {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>inBound()<!>
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
// Unexpected behaviour
|
||||
inline fun <reified T : Out<T>> testOut(): T {
|
||||
<!UNREACHABLE_CODE!>return<!> try {
|
||||
<!IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>outBound<!>()
|
||||
} catch (ex: Exception) {
|
||||
throw Exception()
|
||||
}
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ reified IB : In<IB>> inBound(): IB
|
||||
public inline fun </*0*/ reified TB : Inv<TB>> invBound(): TB
|
||||
public inline fun </*0*/ reified OB : Out<OB>> outBound(): OB
|
||||
public inline fun </*0*/ reified T : In<T>> testIn(): T
|
||||
public inline fun </*0*/ reified T : Inv<T>> testInv(): T
|
||||
public inline fun </*0*/ reified T : Out<T>> testOut(): T
|
||||
|
||||
public final class In</*0*/ in I> {
|
||||
public constructor In</*0*/ in I>()
|
||||
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</*0*/ T> {
|
||||
public constructor Inv</*0*/ T>()
|
||||
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</*0*/ out O> {
|
||||
public constructor Out</*0*/ out O>()
|
||||
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
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
Generated
+5
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user