[NI] Allow capturing type projections with type variables

#KT-25302 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-04-22 17:56:55 +03:00
parent abd1c3df26
commit d40313a8d7
15 changed files with 93 additions and 31 deletions
+1 -1
View File
@@ -6,6 +6,6 @@ import java.util.stream.IntStream
fun main() {
val xs = IntStream.<!INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET_ERROR!>range<!>(0, 10).mapToObj { it.toString() }
.collect(<!NI;NEW_INFERENCE_ERROR!>Collectors.toList()<!>)
.collect(Collectors.toList())
xs[0]
}
@@ -0,0 +1,18 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface CollectorMock<A, R>
interface StreamMock {
fun <R, A> collect(collector: CollectorMock<A, R>): R
}
fun <T> accept(s: T) {}
fun ofK(t: String): StreamMock = TODO()
fun <T> toSetK(): CollectorMock<*, T> = TODO()
class KotlinCollectionUser1 {
fun use() {
accept(ofK("").collect(toSetK<String>()))
}
}
@@ -0,0 +1,26 @@
package
public fun </*0*/ T> accept(/*0*/ s: T): kotlin.Unit
public fun ofK(/*0*/ t: kotlin.String): StreamMock
public fun </*0*/ T> toSetK(): CollectorMock<*, T>
public interface CollectorMock</*0*/ A, /*1*/ R> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class KotlinCollectionUser1 {
public constructor KotlinCollectionUser1()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final fun use(): kotlin.Unit
}
public interface StreamMock {
public abstract fun </*0*/ R, /*1*/ A> collect(/*0*/ collector: CollectorMock<A, R>): R
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,12 +1,11 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Inv<T, K>
class Inv2<T, K>
fun <K> createInv(): Inv<*, K> = TODO()
fun <K> createInv(): Inv2<*, K> = TODO()
fun <T> foo(i: Inv<T, String>) {}
fun <T> foo(i: Inv2<T, String>) {}
fun foo() {
foo(<!NEW_INFERENCE_ERROR!>createInv()<!>)
foo(createInv())
}
@@ -1,11 +1,11 @@
package
public fun </*0*/ K> createInv(): Inv<*, K>
public fun </*0*/ K> createInv(): Inv2<*, K>
public fun foo(): kotlin.Unit
public fun </*0*/ T> foo(/*0*/ i: Inv<T, kotlin.String>): kotlin.Unit
public fun </*0*/ T> foo(/*0*/ i: Inv2<T, kotlin.String>): kotlin.Unit
public final class Inv</*0*/ T, /*1*/ K> {
public constructor Inv</*0*/ T, /*1*/ K>()
public final class Inv2</*0*/ T, /*1*/ K> {
public constructor Inv2</*0*/ T, /*1*/ K>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -59,9 +59,9 @@ fun test1(int: Int, any: Any) {
writeToMyList(getMyListToWriteTo(any), int)
<!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>writeToMyList<!>(getMyListToWriteTo(int), any)
readFromMyList(<!NI;NEW_INFERENCE_ERROR!>getMyListToWriteTo(any)<!>, any)
readFromMyList(getMyListToWriteTo(any), any)
<!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>writeToMyList<!>(<!NI;NEW_INFERENCE_ERROR!>getMyListToReadFrom(any)<!>, any)
<!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>writeToMyList<!>(getMyListToReadFrom(any), <!NI;TYPE_MISMATCH!>any<!>)
use(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
}
@@ -7,8 +7,8 @@ import java.util.stream.Collectors
import java.util.stream.Stream
fun test(a: Stream<String>) {
a.collect(<!NI;NEW_INFERENCE_ERROR!>Collectors.toList()<!>) checkType { _<MutableList<String>>() }
a.collect(Collectors.toList()) checkType { _<MutableList<String>>() }
// actually the inferred type is platform
a.collect(<!NI;NEW_INFERENCE_ERROR!>Collectors.toList()<!>) checkType { _<List<String?>>() }
a.collect(Collectors.toList()) checkType { _<List<String?>>() }
}
@@ -8,6 +8,6 @@ interface A : Collection<String> {
}
fun foo(x: List<String>, y: A) {
x.stream().filter { it.length > 0 }.collect(<!NI;NEW_INFERENCE_ERROR!>Collectors.toList()<!>)
x.stream().filter { it.length > 0 }.collect(Collectors.toList())
y.stream().filter { it.length > 0 }
}