K2: Fix false-positive error with captured types in builder inference

Error arises from the fact that type substitution operation isn't
consistent when applied to captured types.

E.g.:
```
substitution = { A => B }
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_1>
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_2>
C<CapturedType(out B)_1> <!:> C<CapturedType(out B)_2>
```

Relates to KT-53749
This commit is contained in:
Simon Ogorodnik
2023-12-01 15:58:44 +01:00
committed by Space Team
parent d46075a9db
commit c2ddbfc93b
3 changed files with 67 additions and 7 deletions
@@ -26,7 +26,7 @@ fun <K> captureIn(x: Inv<out K>): K = null as K
fun <K> capture(x: Inv<K>): K = null as K
fun main() {
<!NEW_INFERENCE_ERROR!>build {
build {
emit("")
getInv()
captureOut(getInv())
@@ -35,7 +35,7 @@ fun main() {
// K is fixed into CapturedType(out NotFixed: TypeVariable(R))
capture(getOut())
""
}<!>
}
build {
emit("")
// K is fixed into CapturedType(in NotFixed: TypeVariable(R))