105358dcf6
Let's call builder lambdas (BL) a lambda that has non-fixed input type projection at the moment of lambda arguments analysis, such lambdas is a subject to be analyzed with builder inference Due to bug in constraint system joining algorithm, currently system of two or more such lambdas may lead to unsound type inference Diagnostic added here should be reported in case when there are two BL that shares a common constraint system, while not annotated with @BuilderInference, as a protection against aforementioned bug It's reported by ConstraintSystemCompleter when such situation has occurred during builder inference phase, it is the same place that decides wherever lambdas is subject to builder inference or not KT-53740
70 lines
1.8 KiB
Kotlin
Vendored
70 lines
1.8 KiB
Kotlin
Vendored
// WITH_STDLIB
|
|
// SKIP_TXT
|
|
|
|
fun List<Int>.myExt() {}
|
|
fun <T> List<T>.myGenericExt() {}
|
|
|
|
fun <R> a(first: R, second: (List<R>) -> Unit) {}
|
|
|
|
fun test1() {
|
|
a(
|
|
buildList { add("") },
|
|
<!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; a")!>second = {
|
|
it.myGenericExt()
|
|
}<!>
|
|
)
|
|
}
|
|
|
|
|
|
fun <R> b(first: () -> List<R>, second: (List<R>) -> Unit) {}
|
|
|
|
fun test2() {
|
|
b(
|
|
first = {
|
|
buildList { add("") }
|
|
},
|
|
<!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; b")!>second = {
|
|
it.myExt() // Note: must be extension to add constraints
|
|
}<!>
|
|
)
|
|
}
|
|
|
|
fun <Q> select(a: Q, b: Q): Q = a
|
|
|
|
// Note: no builder inference annotation
|
|
fun <R> myBuildList(builder: MutableList<R>.() -> Unit): List<R> {
|
|
val list = mutableListOf<R>()
|
|
list.builder()
|
|
return list
|
|
}
|
|
|
|
fun test3() {
|
|
select(
|
|
buildList { add("") },
|
|
buildList { add(1) }
|
|
)
|
|
|
|
select (
|
|
myBuildList <!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; myBuildList")!>{ add("") }<!>,
|
|
myBuildList <!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; myBuildList")!>{ add(1) }<!>,
|
|
)
|
|
|
|
select (
|
|
run { myBuildList <!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; myBuildList")!>{ add("") }<!> },
|
|
myBuildList <!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("R; myBuildList")!>{ add(1) }<!>,
|
|
)
|
|
}
|
|
|
|
fun <D> buildPartList(left: MutableList<D>.() -> Unit, right: MutableList<D>.() -> Unit): List<D> {
|
|
val list = mutableListOf<D>()
|
|
list.left()
|
|
list.right()
|
|
return list
|
|
}
|
|
|
|
fun test4() {
|
|
buildPartList(
|
|
<!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("D; buildPartList")!>left = { add(1) }<!>,
|
|
<!BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION("D; buildPartList")!>right = { add("") }<!>
|
|
)
|
|
} |