Redundant/conflicting projections

This commit is contained in:
Andrey Breslav
2012-11-22 12:52:14 +04:00
parent 5b93ae2d08
commit c849a0c4e3
24 changed files with 79 additions and 42 deletions
@@ -7,7 +7,7 @@ import <!UNRESOLVED_REFERENCE!>utils<!>.*
import java.io.PrintStream
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Com
val l : List<in Int> = ArrayList<Int>()
val l : MutableList<in Int> = ArrayList<Int>()
fun test(<!UNUSED_PARAMETER!>l<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<Int><!>) {
val <!UNUSED_VARIABLE!>x<!> : java.<!UNRESOLVED_REFERENCE!>List<!>
@@ -0,0 +1,20 @@
class In<in T>
class Out<out T>
class Inv<T>
class X
fun f1(<!UNUSED_PARAMETER!>p<!>: In<<!REDUNDANT_PROJECTION!>in<!> X>) {}
fun f2(<!UNUSED_PARAMETER!>p<!>: In<<!CONFLICTING_PROJECTION!>out<!> X>) {}
fun f3(<!UNUSED_PARAMETER!>p<!>: In<X>) {}
fun f4(<!UNUSED_PARAMETER!>p<!>: Out<<!REDUNDANT_PROJECTION!>out<!> X>) {}
fun f5(<!UNUSED_PARAMETER!>p<!>: Out<<!CONFLICTING_PROJECTION!>in<!> X>) {}
fun f6(<!UNUSED_PARAMETER!>p<!>: Out<X>) {}
fun f6(<!UNUSED_PARAMETER!>p<!>: Inv<X>) {}
fun f7(<!UNUSED_PARAMETER!>p<!>: Inv<in X>) {}
fun f8(<!UNUSED_PARAMETER!>p<!>: Inv<out X>) {}
fun f9(<!UNUSED_PARAMETER!>p<!>: In<*>) {}
fun f10(<!UNUSED_PARAMETER!>p<!>: Out<*>) {}
fun f11(<!UNUSED_PARAMETER!>p<!>: Inv<*>) {}
@@ -17,24 +17,19 @@ class Inv<T>() {
fun testInOut() {
In<String>().f("1");
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<in String>).f("1")
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<out String>).f(<!TYPE_MISMATCH!>"1"<!>) // Wrong Arg
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<<!REDUNDANT_PROJECTION!>in<!> String>).f("1")
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<*>).f(<!TYPE_MISMATCH!>"1"<!>) // Wrong Arg
In<String>().f(1);
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<in String>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<out String>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<out String>).<!UNRESOLVED_REFERENCE!>f1<!>(1) // !!
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<<!REDUNDANT_PROJECTION!>in<!> String>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> In<*>).f(1);
Out<Int>().f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<out Int>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<in Int>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<<!REDUNDANT_PROJECTION!>out<!> Int>).f(1)
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<*>).f(1)
Out<Int>().f()
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<out Int>).f()
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<in Int>).f()
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<<!REDUNDANT_PROJECTION!>out<!> Int>).f()
(null <!CAST_NEVER_SUCCEEDS!>as<!> Out<*>).f()
Inv<Int>().f(1)
@@ -36,8 +36,8 @@ fun test1() {
val i = both(1, "")
val j = both(id(1), id(""))
i : Comparable<out Any?>
j : Comparable<out Any?>
i : Comparable<*>
j : Comparable<*>
}
fun list<T>(value: T) : ArrayList<T> {
@@ -2,7 +2,7 @@
//+JDK
package d
public fun <T> Collection<out T>.filterToMy(result : MutableList<in T>, filter : (T) -> Boolean) : Collection<out T> {
public fun <T> MutableCollection<out T>.filterToMy(result : MutableList<in T>, filter : (T) -> Boolean) : MutableCollection<out T> {
for (t in this){
if (filter(t)){
result.add(t)
@@ -11,13 +11,13 @@ public fun <T> Collection<out T>.filterToMy(result : MutableList<in T>, filter :
return this
}
fun foo(result: MutableList<in String>, val collection: Collection<String>, prefix : String){
fun foo(result: MutableList<in String>, val collection: MutableCollection<String>, prefix : String){
collection.filterToMy(result, {it.startsWith(prefix)})
}
fun test(result: MutableList<in Any>, val collection: Collection<String>, prefix : String){
fun test(result: MutableList<in Any>, val collection: MutableCollection<String>, prefix : String){
val c = collection.filterToMy(result, {it.startsWith(prefix)})
c: Collection<out String>
c: MutableCollection<out String>
}
//from library
@@ -13,9 +13,9 @@ fun foo() : G<Point> {
class Out<out T>() {}
fun fout<T>(<!UNUSED_PARAMETER!>expression<!> : T) : Out<out T> = Out<T>()
fun fout<T>(<!UNUSED_PARAMETER!>expression<!> : T) : Out<<!REDUNDANT_PROJECTION!>out<!> T> = Out<T>()
fun fooout() : Out<Point> {
val p = Point();
return fout<Point>(p);
}
}