Determine empty constraint system for a builder inference call by presense of not fixed type variables
This commit is contained in:
+13
-7
@@ -12693,18 +12693,24 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints")
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class AddingConstraints {
|
||||
public class Constraints {
|
||||
@Test
|
||||
public void testAllFilesPresentInAddingConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
public void testAllFilesPresentInConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/constraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("bySpecifiedReturnType.kt")
|
||||
public void testBySpecifiedReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints/bySpecifiedReturnType.kt");
|
||||
@TestMetadata("violating.kt")
|
||||
public void testViolating() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withExpectedType.kt")
|
||||
public void testWithExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-7
@@ -12693,18 +12693,24 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints")
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class AddingConstraints {
|
||||
public class Constraints {
|
||||
@Test
|
||||
public void testAllFilesPresentInAddingConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
public void testAllFilesPresentInConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/constraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("bySpecifiedReturnType.kt")
|
||||
public void testBySpecifiedReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints/bySpecifiedReturnType.kt");
|
||||
@TestMetadata("violating.kt")
|
||||
public void testViolating() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withExpectedType.kt")
|
||||
public void testWithExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-17
@@ -267,7 +267,7 @@ class BuilderInferenceSession(
|
||||
storage: ConstraintStorage,
|
||||
nonFixedToVariablesSubstitutor: NewTypeSubstitutor,
|
||||
shouldIntegrateAllConstraints: Boolean
|
||||
): Boolean {
|
||||
) {
|
||||
storage.notFixedTypeVariables.values.forEach {
|
||||
if (it.typeVariable.freshTypeConstructor(commonSystem.typeSystemContext) !in commonSystem.allTypeVariables) {
|
||||
commonSystem.registerVariable(it.typeVariable)
|
||||
@@ -287,8 +287,6 @@ class BuilderInferenceSession(
|
||||
* */
|
||||
val callSubstitutor = storage.buildResultingSubstitutor(commonSystem, transformTypeVariablesToErrorTypes = false)
|
||||
|
||||
var introducedConstraint = false
|
||||
|
||||
for (initialConstraint in storage.initialConstraints) {
|
||||
val lowerCallSubstituted = callSubstitutor.safeSubstitute(initialConstraint.a as UnwrappedType)
|
||||
val upperCallSubstituted = callSubstitutor.safeSubstitute(initialConstraint.b as UnwrappedType)
|
||||
@@ -297,8 +295,6 @@ class BuilderInferenceSession(
|
||||
|
||||
if (commonSystem.isProperType(lower) && commonSystem.isProperType(upper)) continue
|
||||
|
||||
introducedConstraint = true
|
||||
|
||||
when (initialConstraint.constraintKind) {
|
||||
ConstraintKind.LOWER -> error("LOWER constraint shouldn't be used, please use UPPER")
|
||||
|
||||
@@ -317,11 +313,8 @@ class BuilderInferenceSession(
|
||||
val typeVariable = storage.allTypeVariables.getValue(variableConstructor)
|
||||
commonSystem.registerVariable(typeVariable)
|
||||
commonSystem.addEqualityConstraint((typeVariable as NewTypeVariable).defaultType, type, CoroutinePosition)
|
||||
introducedConstraint = true
|
||||
}
|
||||
}
|
||||
|
||||
return introducedConstraint
|
||||
}
|
||||
|
||||
fun addExpectedTypeConstraint(
|
||||
@@ -379,20 +372,14 @@ class BuilderInferenceSession(
|
||||
|
||||
integrateConstraints(initialStorage, nonFixedToVariablesSubstitutor, false)
|
||||
|
||||
var effectivelyEmptyCommonSystem = true
|
||||
|
||||
for (call in commonCalls) {
|
||||
val hasConstraints =
|
||||
integrateConstraints(call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, false)
|
||||
if (hasConstraints) effectivelyEmptyCommonSystem = false
|
||||
integrateConstraints(call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, false)
|
||||
}
|
||||
for (call in partiallyResolvedCallsInfo) {
|
||||
val hasConstraints =
|
||||
integrateConstraints(call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, true)
|
||||
if (hasConstraints) effectivelyEmptyCommonSystem = false
|
||||
integrateConstraints(call.callResolutionResult.constraintSystem, nonFixedToVariablesSubstitutor, true)
|
||||
}
|
||||
|
||||
return effectivelyEmptyCommonSystem
|
||||
return commonSystem.notFixedTypeVariables.all { it.value.constraints.isEmpty() }
|
||||
}
|
||||
|
||||
private fun reportErrors(completedCall: CallInfo, resolvedCall: ResolvedCall<*>, errors: List<ConstraintSystemError>) {
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface A {
|
||||
fun foo(): MutableList<String>
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
fun main() {
|
||||
buildList {
|
||||
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
|
||||
object : A {
|
||||
override fun foo(): MutableList<String> = this@buildList
|
||||
}
|
||||
}
|
||||
buildList {
|
||||
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
|
||||
val x: String = get(0)
|
||||
}
|
||||
buildList {
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>"3"<!>)
|
||||
val x: MutableList<Int> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
val y: CharSequence = ""
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>y<!>)
|
||||
val x: MutableList<String> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
add("")
|
||||
val x: MutableList<CharSequence> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>""<!>)
|
||||
val x: StringBuilder = get(0)
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package
|
||||
|
||||
@kotlin.ExperimentalStdlibApi public fun main(): kotlin.Unit
|
||||
|
||||
public interface A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.collections.MutableList<kotlin.String>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+3
@@ -33,4 +33,7 @@ fun main() {
|
||||
add("")
|
||||
val x: StringBuilder = get(0)
|
||||
}
|
||||
buildMap {
|
||||
val x: Function2<String, Char, Char?> = ::put
|
||||
}
|
||||
}
|
||||
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
// WITH_RUNTIME
|
||||
// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR
|
||||
|
||||
interface A {
|
||||
fun foo(): MutableList<String>
|
||||
}
|
||||
|
||||
fun <K> id(x: K): K = x
|
||||
|
||||
fun <K, V> build(@BuilderInference builderAction: MutableMap<K, V>.() -> V) {}
|
||||
|
||||
fun <K, V> build2(@BuilderInference builderAction: MutableMap<K, V>.() -> K) {}
|
||||
|
||||
fun <K, V> build3(@BuilderInference builderAction: MutableMap<K, V>.(K) -> Unit) {}
|
||||
|
||||
fun <K, V> build4(@BuilderInference builderAction: MutableMap<K, V>.() -> MutableMap<String, Int>) {}
|
||||
|
||||
fun <K : V, V : CharSequence> build5(@BuilderInference builderAction: MutableMap<K, V>.() -> MutableMap<String, V>) {}
|
||||
|
||||
fun <K : V, V : CharSequence> build6(@BuilderInference builderAction: MutableMap<K, V>.() -> MutableMap<K, String>) {}
|
||||
|
||||
fun <K : V, V : CharSequence> build7(@BuilderInference builderAction: MutableMap<K, V>.() -> MutableMap<String, V>): MutableMap<String, V> {}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
fun main() {
|
||||
buildList {
|
||||
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
|
||||
object : A {
|
||||
override fun foo(): MutableList<String> = this@buildList
|
||||
}
|
||||
}
|
||||
buildList {
|
||||
add(<!CONSTANT_EXPECTED_TYPE_MISMATCH, CONSTANT_EXPECTED_TYPE_MISMATCH!>3<!>)
|
||||
val x: String = get(0)
|
||||
}
|
||||
buildList {
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>"3"<!>)
|
||||
val x: MutableList<Int> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
val y: CharSequence = ""
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>y<!>)
|
||||
val x: MutableList<String> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
add("")
|
||||
val x: MutableList<CharSequence> = this@buildList
|
||||
}
|
||||
buildList {
|
||||
add(<!TYPE_MISMATCH, TYPE_MISMATCH!>""<!>)
|
||||
val x: StringBuilder = get(0)
|
||||
}
|
||||
buildMap {
|
||||
val x: Function2<String, Char, Char?> = ::put
|
||||
}
|
||||
|
||||
build {
|
||||
get("")
|
||||
""
|
||||
}
|
||||
|
||||
build2 {
|
||||
val x: String = this.values.first()
|
||||
1
|
||||
}
|
||||
|
||||
build2 {
|
||||
take(this.values.first())
|
||||
1
|
||||
}
|
||||
|
||||
build3 { key: String ->
|
||||
take(this.values.first())
|
||||
}
|
||||
|
||||
build3 { this.foo() }
|
||||
|
||||
build4 { this }
|
||||
|
||||
build4 { this.run { this } }
|
||||
|
||||
build4 { run { this } }
|
||||
build4 { id(run { this }) }
|
||||
|
||||
build5 { id(run { this }) }
|
||||
build6 { id(run { this }) }
|
||||
|
||||
val x: MutableMap<String, CharSequence> = build7 {
|
||||
id(run { this })
|
||||
}
|
||||
}
|
||||
|
||||
fun MutableMap<String, Int>.foo() {}
|
||||
|
||||
fun take(x: String) {}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ K, /*1*/ V> build(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.() -> V): kotlin.Unit
|
||||
public fun </*0*/ K, /*1*/ V> build2(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.() -> K): kotlin.Unit
|
||||
public fun </*0*/ K, /*1*/ V> build3(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.(K) -> kotlin.Unit): kotlin.Unit
|
||||
public fun </*0*/ K, /*1*/ V> build4(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.() -> kotlin.collections.MutableMap<kotlin.String, kotlin.Int>): kotlin.Unit
|
||||
public fun </*0*/ K : V, /*1*/ V : kotlin.CharSequence> build5(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.() -> kotlin.collections.MutableMap<kotlin.String, V>): kotlin.Unit
|
||||
public fun </*0*/ K : V, /*1*/ V : kotlin.CharSequence> build6(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap<K, V>.() -> kotlin.collections.MutableMap<K, kotlin.String>): kotlin.Unit
|
||||
public fun </*0*/ K> id(/*0*/ x: K): K
|
||||
@kotlin.ExperimentalStdlibApi public fun main(): kotlin.Unit
|
||||
public fun take(/*0*/ x: kotlin.String): kotlin.Unit
|
||||
public fun kotlin.collections.MutableMap<kotlin.String, kotlin.Int>.foo(): kotlin.Unit
|
||||
|
||||
public interface A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.collections.MutableList<kotlin.String>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+13
-7
@@ -12699,18 +12699,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints")
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class AddingConstraints {
|
||||
public class Constraints {
|
||||
@Test
|
||||
public void testAllFilesPresentInAddingConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
public void testAllFilesPresentInConstraints() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/builderInference/constraints"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("bySpecifiedReturnType.kt")
|
||||
public void testBySpecifiedReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/addingConstraints/bySpecifiedReturnType.kt");
|
||||
@TestMetadata("violating.kt")
|
||||
public void testViolating() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withExpectedType.kt")
|
||||
public void testWithExpectedType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user