K2: Don't lose constraint errors in the builder inference session

Pass constraint errors from the integration system into a candidate to
make sure it is reported later.

Related to KT-59426, KT-59437, KT-53749
#KT-55168 Submitted
This commit is contained in:
Simon Ogorodnik
2023-11-29 11:58:29 +01:00
committed by Space Team
parent cb3d65f669
commit 2f367b013a
26 changed files with 99 additions and 62 deletions
@@ -1,8 +1,8 @@
// ISSUE: KT-55168
fun foo(arg: Boolean) = buildList {
fun foo(arg: Boolean) = <!NEW_INFERENCE_ERROR!>buildList {
if (arg) {
removeLast()
} else {
add(42)
}
}
}<!>
@@ -0,0 +1 @@
/inconsistentTypeInference.fir.kt:(62,127): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call: kotlin/String <!: kotlin/Int].
@@ -2,9 +2,9 @@
// FIR_DUMP
fun foo() {
buildList {
<!NEW_INFERENCE_ERROR!>buildList {
add("Boom")
println(plus(1)[0])
}
}<!>
}
@@ -1,6 +1,6 @@
FILE: inconsistentTypeInference.fir.kt
public final fun foo(): R|kotlin/Unit| {
R|kotlin/collections/buildList|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
R|kotlin/collections/buildList<CS errors: kotlin/collections/buildList>#|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(String(Boom))
R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|<R|kotlin/Int|>(Int(1)).R|SubstitutionOverride<kotlin/collections/List.get: R|kotlin/Int|>|(Int(0)))
}
@@ -0,0 +1 @@
/inconsistentTypeInference2.fir.kt:(62,132): error: New inference error [NewConstraintError at Incorporate kotlin/collections/MutableList<TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call from position Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<kotlin/Int> from Incorporated builder inference constraint kotlin/collections/MutableList<Stub (chain inference): TypeVariable(E)> <: kotlin/collections/Collection<TypeVariable(T)> from Receiver this@R|special/anonymous| into some call into some call: kotlin/String <!: kotlin/Int].
@@ -2,8 +2,8 @@
// FIR_DUMP
fun bar() {
buildList {
<!NEW_INFERENCE_ERROR!>buildList {
add("Boom")
println(this.plus(1)[0])
}
}
}<!>
}
@@ -1,6 +1,6 @@
FILE: inconsistentTypeInference2.fir.kt
public final fun bar(): R|kotlin/Unit| {
R|kotlin/collections/buildList|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
R|kotlin/collections/buildList<CS errors: kotlin/collections/buildList>#|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(String(Boom))
R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|<R|kotlin/Int|>(Int(1)).R|SubstitutionOverride<kotlin/collections/List.get: R|kotlin/Int|>|(Int(0)))
}
@@ -7,7 +7,7 @@ fun <T : Any> myBuilder(block: Foo<T>.() -> Unit) : Foo<T> = Foo<T>().apply(bloc
fun main(arg: Any) {
val x = 57
val value = myBuilder {
val value = <!NEW_INFERENCE_ERROR!>myBuilder {
doSmthng("one ")
run { a; this }.a = 10
<!BUILDER_INFERENCE_STUB_RECEIVER!>a += 1<!>
@@ -19,6 +19,6 @@ fun main(arg: Any) {
if (arg is String) {
a = arg
}
}
}<!>
<!OVERLOAD_RESOLUTION_AMBIGUITY!>println<!>(value.a?.<!UNRESOLVED_REFERENCE!>count<!> { <!UNRESOLVED_REFERENCE!>it<!> in 'l' .. 'q' })
}
@@ -60,18 +60,18 @@ fun main(arg: Any, condition: Boolean) {
}
// See KT-54664
val value3 = myBuilder {
val value3 = <!NEW_INFERENCE_ERROR!>myBuilder {
accept("")
a = 45
bar(::a)
}
}<!>
fun baz(t: Int) {}
val value4 = myBuilder {
val value4 = <!NEW_INFERENCE_ERROR!>myBuilder {
accept("")
a = 45
b[0] = 123
baz(a)
}
}<!>
}
@@ -91,7 +91,7 @@ FILE: unsafeAssignmentExtra.fir.kt
}
)
lval value3: R|Foo<kotlin/Int>| = R|/myBuilder|<R|kotlin/Int|>(<L> = myBuilder@fun R|Foo<kotlin/Int>|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
lval value3: R|Foo<kotlin/Int>| = R|/myBuilder<CS errors: /myBuilder>#|<R|kotlin/Int|>(<L> = myBuilder@fun R|Foo<kotlin/Int>|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
this@R|special/anonymous|.R|SubstitutionOverride</Foo.accept: R|kotlin/Unit|>|(String())
this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>| = Int(45)
R|/bar|(::R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>|)
@@ -100,7 +100,7 @@ FILE: unsafeAssignmentExtra.fir.kt
local final fun baz(t: R|kotlin/Int|): R|kotlin/Unit| {
}
lval value4: R|Foo<it(kotlin/Comparable<*> & java/io/Serializable)>| = R|/myBuilder|<R|it(kotlin/Comparable<*> & java/io/Serializable)|>(<L> = myBuilder@fun R|Foo<it(kotlin/Comparable<*> & java/io/Serializable)>|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
lval value4: R|Foo<it(kotlin/Comparable<*> & java/io/Serializable)>| = R|/myBuilder<CS errors: /myBuilder>#|<R|it(kotlin/Comparable<*> & java/io/Serializable)|>(<L> = myBuilder@fun R|Foo<it(kotlin/Comparable<*> & java/io/Serializable)>|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
this@R|special/anonymous|.R|SubstitutionOverride</Foo.accept: R|kotlin/Unit|>|(String())
this@R|special/anonymous|.R|SubstitutionOverride</Foo.a: R|Stub (chain inference): TypeVariable(T)|>| = Int(45)
this@R|special/anonymous|.R|SubstitutionOverride</Foo.b: R|kotlin/Array<Stub (chain inference): TypeVariable(T)>|>|.R|SubstitutionOverride<kotlin/Array.set: R|kotlin/Unit|>|(Int(0), Int(123))
@@ -0,0 +1 @@
/upperBoundViolation.fir.kt:(150,260): error: New inference error [NewConstraintError at Incorporate TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint Stub (chain inference): TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call into some call from position Incorporated builder inference constraint Stub (chain inference): TypeVariable(E) <: kotlin/Number from Incorporated builder inference constraint TypeVariable(T) <: kotlin/Number from DeclaredUpperBound into some call into some call: kotlin/String <!: kotlin/Number].
@@ -4,8 +4,8 @@
fun <T : Number> printGenericNumber(t: T) = println("Number is $t")
fun main() {
buildList { // inferred into MutableList<String>
<!NEW_INFERENCE_ERROR!>buildList { // inferred into MutableList<String>
add("Boom")
printGenericNumber(this[0])
}
}<!>
}
@@ -3,7 +3,7 @@ FILE: upperBoundViolation.fir.kt
^printGenericNumber R|kotlin/io/println|(<strcat>(String(Number is ), R|<local>/t|))
}
public final fun main(): R|kotlin/Unit| {
R|kotlin/collections/buildList|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
R|kotlin/collections/buildList<CS errors: kotlin/collections/buildList>#|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(String(Boom))
R|/printGenericNumber|<R|kotlin/String|>(this@R|special/anonymous|.R|SubstitutionOverride<kotlin/collections/MutableList.get: R|Stub (chain inference): TypeVariable(E)|>|(Int(0)))
}