Fix inference issue with Stream.collect

See doNotCaptureSupertype test for clarification:
When resolving b.collect(toList()) we're building a common system with
two variables T and R.

The problem was that when introducing the constraint
C<T, Inv<T>> <: C<in String, R> we then were seeing the constraint
T <= in String, and add the constaint T=Captured(in String)

That lead to R=Inv<T>=Inv<Captured(in String)>, and after approximation
R=Inv<in String>, that is not the desirable result (Inv<String> suits here)

But the root problem was that we add captured constaint when projection was from supertype,
that seems to be wrong, and for example Java doesn't do that in the similar situation.

 #KT-11259 Fixed
This commit is contained in:
Denis Zharkov
2017-01-20 15:32:05 +03:00
parent a18720154c
commit 2edcd369a8
6 changed files with 45 additions and 10 deletions
@@ -0,0 +1,11 @@
// !CHECK_TYPE
// SKIP_TXT
import java.util.stream.Collectors
import java.util.stream.Stream
fun test(a: Stream<String>) {
a.collect(Collectors.toList()) checkType { _<MutableList<String>>() }
// actually the inferred type is platform
a.collect(Collectors.toList()) checkType { _<List<String?>>() }
}