[FE 1.0] Skip improper constraints while determining READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES type variable readiness
^KT-51148 Fixed
This commit is contained in:
committed by
teamcity
parent
500295da68
commit
c25e07119c
+6
@@ -14243,6 +14243,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt50989.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51148.kt")
|
||||
public void testKt51148() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labaledCall.kt")
|
||||
public void testLabaledCall() throws Exception {
|
||||
|
||||
+6
@@ -14243,6 +14243,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt50989.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51148.kt")
|
||||
public void testKt51148() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labaledCall.kt")
|
||||
public void testLabaledCall() throws Exception {
|
||||
|
||||
+6
@@ -14243,6 +14243,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt50989.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51148.kt")
|
||||
public void testKt51148() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labaledCall.kt")
|
||||
public void testLabaledCall() throws Exception {
|
||||
|
||||
+23
-7
@@ -67,7 +67,7 @@ class VariableFixationFinder(
|
||||
): TypeVariableFixationReadiness = when {
|
||||
!notFixedTypeVariables.contains(variable) ||
|
||||
dependencyProvider.isVariableRelatedToTopLevelType(variable) -> TypeVariableFixationReadiness.FORBIDDEN
|
||||
isTypeInferenceForSelfTypesSupported && hasOnlyDeclaredUpperBoundSelfTypes(variable) ->
|
||||
isTypeInferenceForSelfTypesSupported && areAllProperConstraintsSelfTypeBased(variable) ->
|
||||
TypeVariableFixationReadiness.READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES
|
||||
!variableHasProperArgumentConstraints(variable) -> TypeVariableFixationReadiness.WITHOUT_PROPER_ARGUMENT_CONSTRAINT
|
||||
hasDependencyToOtherTypeVariables(variable) -> TypeVariableFixationReadiness.WITH_COMPLEX_DEPENDENCY
|
||||
@@ -175,13 +175,29 @@ class VariableFixationFinder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun Context.hasOnlyDeclaredUpperBoundSelfTypes(variable: TypeConstructorMarker): Boolean {
|
||||
val constraints = notFixedTypeVariables[variable]?.constraints ?: return false
|
||||
return constraints.isNotEmpty() && constraints.all {
|
||||
val typeConstructor = it.type.typeConstructor()
|
||||
it.position.from is DeclaredUpperBoundConstraintPosition<*>
|
||||
&& (hasRecursiveTypeParametersWithGivenSelfType(typeConstructor) || isRecursiveTypeParameter(typeConstructor))
|
||||
private fun Context.isSelfTypeConstraint(constraint: Constraint): Boolean {
|
||||
val typeConstructor = constraint.type.typeConstructor()
|
||||
return constraint.position.from is DeclaredUpperBoundConstraintPosition<*>
|
||||
&& (hasRecursiveTypeParametersWithGivenSelfType(typeConstructor) || isRecursiveTypeParameter(typeConstructor))
|
||||
}
|
||||
|
||||
private fun Context.areAllProperConstraintsSelfTypeBased(variable: TypeConstructorMarker): Boolean {
|
||||
val constraints = notFixedTypeVariables[variable]?.constraints?.takeIf { it.isNotEmpty() } ?: return false
|
||||
|
||||
var hasSelfTypeConstraint = false
|
||||
var hasOtherProperConstraint = false
|
||||
|
||||
for (constraint in constraints) {
|
||||
if (isSelfTypeConstraint(constraint)) {
|
||||
hasSelfTypeConstraint = true
|
||||
}
|
||||
if (isProperArgumentConstraint(constraint)) {
|
||||
hasOtherProperConstraint = true
|
||||
}
|
||||
if (hasSelfTypeConstraint && hasOtherProperConstraint) break
|
||||
}
|
||||
|
||||
return hasSelfTypeConstraint && !hasOtherProperConstraint
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun box(): String {
|
||||
return <!INAPPLICABLE_CANDIDATE!>someFunction<!><<!CANNOT_INFER_PARAMETER_TYPE!>SomeEnum<!>>()
|
||||
}
|
||||
|
||||
interface SomeInterface <V> {
|
||||
|
||||
val value: V
|
||||
|
||||
}
|
||||
|
||||
enum class SomeEnum {
|
||||
|
||||
A, B, C
|
||||
|
||||
}
|
||||
|
||||
fun <V, T> someFunction(): String where T : Enum<T>, T : SomeInterface<V> {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fun box(): String {
|
||||
return <!TYPE_MISMATCH!>someFunction<!><!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><SomeEnum><!>()
|
||||
}
|
||||
|
||||
interface SomeInterface <V> {
|
||||
|
||||
val value: V
|
||||
|
||||
}
|
||||
|
||||
enum class SomeEnum {
|
||||
|
||||
A, B, C
|
||||
|
||||
}
|
||||
|
||||
fun <V, T> someFunction(): String where T : Enum<T>, T : SomeInterface<V> {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.String
|
||||
public fun </*0*/ V, /*1*/ T : kotlin.Enum<T>> someFunction(): kotlin.String where T : SomeInterface<V>
|
||||
|
||||
public final enum class SomeEnum : kotlin.Enum<SomeEnum> {
|
||||
enum entry A
|
||||
|
||||
enum entry B
|
||||
|
||||
enum entry C
|
||||
|
||||
private constructor SomeEnum()
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: SomeEnum): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<SomeEnum!>!
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): SomeEnum
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<SomeEnum>
|
||||
}
|
||||
|
||||
public interface SomeInterface</*0*/ V> {
|
||||
public abstract val value: V
|
||||
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
|
||||
}
|
||||
Generated
+6
@@ -14249,6 +14249,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt50989.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt51148.kt")
|
||||
public void testKt51148() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("labaledCall.kt")
|
||||
public void testLabaledCall() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user