Add constraints between two different stub variables instead of creating constraint error due to T1 isn't subtype of T2
^KT-44241 Fixed
This commit is contained in:
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// !LANGUAGE: +UnrestrictedBuilderInference
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
class Foo<K11, K22>(val key: K11) {
|
||||
fun emit1(key: K11) {}
|
||||
fun get(): K11 = null as K11
|
||||
fun emit2(key: K22) {}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <K1, K2> build(@kotlin.BuilderInference builder: Foo<K1, K2>.() -> Unit) {}
|
||||
|
||||
fun run(x: Int) {
|
||||
build {
|
||||
emit1(x)
|
||||
emit2(get()) // We shouldn't report type mismatch, instead we should add constraint StubTypeVariable(K2) >: StubTypeVariable(K1), then infer K2 into Int among K1
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
run(1)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user