KT-8879 Stackoverflow exception on completion from inference
#KT-8879 Fixed Added ConstraintContext storing 'derivedFrom' variables. This information is used to prevent infinite recursion: if a variable was substituted in a type of a bound, it shouldn't be substituted there for the second time.
This commit is contained in:
@@ -6,6 +6,7 @@ interface C : B
|
||||
|
||||
interface Consumer<in T>
|
||||
interface Producer<out T>
|
||||
interface Inv<T>
|
||||
|
||||
interface My<T>
|
||||
interface Successor<T> : My<T>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
VARIABLES T P
|
||||
|
||||
T <: My<T>
|
||||
Inv<P> <: Inv<T>
|
||||
|
||||
type parameter bounds:
|
||||
T <: My<T>*, := P*, <: My<out My<T>>*, <: My<P>*, <: My<out My<P>>*, <: My<out My<out My<T>>>*
|
||||
P := T*, <: My<T>*, <: My<out My<T>>*, <: My<P>*, <: My<out My<P>>*, <: My<out My<out My<T>>>*
|
||||
|
||||
status:
|
||||
-hasCannotCaptureTypesError: false
|
||||
-hasConflictingConstraints: false
|
||||
-hasContradiction: false
|
||||
-hasErrorInConstrainingTypes: false
|
||||
-hasParameterConstraintError: false
|
||||
-hasTypeInferenceIncorporationError: false
|
||||
-hasUnknownParameters: true
|
||||
-hasViolatedUpperBound: false
|
||||
-isSuccessful: false
|
||||
|
||||
result:
|
||||
T=???
|
||||
P=???
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
VARIABLES T P
|
||||
|
||||
T <: My<T>
|
||||
Inv<P> <: Inv<T>
|
||||
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Inv<I>
|
||||
interface Inv2<I>
|
||||
|
||||
fun <T: Inv2<T>> foo(klass: Inv<T>): String? = null
|
||||
|
||||
fun <X> bar(): Inv<X> = null!!
|
||||
|
||||
fun test() {
|
||||
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>())
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package
|
||||
|
||||
internal fun </*0*/ X> bar(): Inv<X>
|
||||
internal fun </*0*/ T : Inv2<T>> foo(/*0*/ klass: Inv<T>): kotlin.String?
|
||||
internal fun test(): kotlin.Unit
|
||||
|
||||
internal interface Inv</*0*/ 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
|
||||
}
|
||||
|
||||
internal interface Inv2</*0*/ 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
|
||||
}
|
||||
@@ -7226,6 +7226,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt8879.kt")
|
||||
public void testKt8879() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notNullConstraintOnNullableType.kt")
|
||||
public void testNotNullConstraintOnNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/constraints/notNullConstraintOnNullableType.kt");
|
||||
|
||||
+5
-4
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.SPECIAL
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.registerTypeVariables
|
||||
@@ -92,12 +93,12 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() {
|
||||
for (constraint in constraints) {
|
||||
val firstType = testDeclarations.getType(constraint.firstType).assertNotError()
|
||||
val secondType = testDeclarations.getType(constraint.secondType).assertNotError()
|
||||
val position = SPECIAL.position()
|
||||
val context = ConstraintContext(SPECIAL.position())
|
||||
when (constraint.kind) {
|
||||
MyConstraintKind.SUBTYPE -> constraintSystem.addSubtypeConstraint(firstType, secondType, position)
|
||||
MyConstraintKind.SUPERTYPE -> constraintSystem.addSupertypeConstraint(firstType, secondType, position)
|
||||
MyConstraintKind.SUBTYPE -> constraintSystem.addSubtypeConstraint(firstType, secondType, context.position)
|
||||
MyConstraintKind.SUPERTYPE -> constraintSystem.addSupertypeConstraint(firstType, secondType, context.position)
|
||||
MyConstraintKind.EQUAL -> constraintSystem.addConstraint(
|
||||
ConstraintSystemImpl.ConstraintKind.EQUAL, firstType, secondType, position, topLevel = true)
|
||||
ConstraintSystemImpl.ConstraintKind.EQUAL, firstType, secondType, context, topLevel = true)
|
||||
}
|
||||
}
|
||||
if (fixVariables) constraintSystem.fixVariables()
|
||||
|
||||
+6
@@ -720,6 +720,12 @@ public class ConstraintSystemTestGenerated extends AbstractConstraintSystemTest
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt8879.constraints")
|
||||
public void testKt8879() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/severalVariables/recursive/kt8879.constraints");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("mutuallyRecursive.constraints")
|
||||
public void testMutuallyRecursive() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/constraintSystem/severalVariables/recursive/mutuallyRecursive.constraints");
|
||||
|
||||
Reference in New Issue
Block a user