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:
@@ -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?>>() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user