Merge remote branch 'origin/master'

This commit is contained in:
Alex Tkachman
2011-11-24 22:33:13 +02:00
35 changed files with 333 additions and 61 deletions
@@ -0,0 +1,4 @@
import java.util.List;
import java.util.Collection;
fun ff(c: Collection<String>) = c <!CAST_NEVER_SUCCEEDS!>as<!> List<Int>
@@ -0,0 +1,4 @@
import java.util.List;
import java.util.Collection;
fun ff(c: Collection<String>) = c as List<String>
@@ -0,0 +1,4 @@
import java.util.List;
fun ff(l: Any) = l as List<*>
@@ -0,0 +1,3 @@
import java.util.List;
fun ff(a: Any) = <!UNCHECKED_CAST!>a as List<String><!>
@@ -0,0 +1,5 @@
import java.util.Collection;
import java.util.List;
fun ff(l: Collection<String>) = l is List<String>
@@ -0,0 +1,9 @@
import java.util.Collection;
import java.util.List;
open class A
class B : A
fun ff(l: Collection<B>) = l is List<out A>
@@ -0,0 +1,3 @@
import java.util.List;
fun ff(l: Any) = l is <!CANNOT_CHECK_FOR_ERASED!>List<String><!>
@@ -0,0 +1,3 @@
import java.util.List;
fun ff(l: Any) = l is List<*>
@@ -0,0 +1,3 @@
class MyList<T>
fun ff(a: Any) = a is MyList<String>
@@ -0,0 +1,4 @@
trait Aaa
trait Bbb
fun f(a: Aaa) = a is Bbb
@@ -0,0 +1,6 @@
import java.util.List;
fun ff(l: Any) = when(l) {
is <!CANNOT_CHECK_FOR_ERASED!>List<String><!> => 1
else 2
}
@@ -0,0 +1,8 @@
//KT-600 Problem with 'sure' extension function type inference
fun <T : Any> T?.sure() : T { if (this != null) return this else throw NullPointerException() }
fun test() {
val i : Int? = 10
val <!UNUSED_VARIABLE!>i2<!> : Int = i.sure() // inferred type is Int? but Int was excepted
}
@@ -0,0 +1,16 @@
//KT-549 type inference failed
namespace demo
fun filter<T>(list : Array<T>, filter : fun (T) : Boolean) : java.util.List<T> {
val answer = java.util.ArrayList<T>();
for (l in list) {
if (filter(l)) answer.add(l)
}
return answer;
}
fun main(args : Array<String>) {
for (a in filter(args, {it.length > 1})) {
System.out?.println("Hello, ${a}!")
}
}
@@ -0,0 +1,20 @@
//KT-580 Type inference failed
namespace whats.the.difference
import java.util.*
fun iarray(vararg a : String) = a // BUG
fun main(vals : IntArray) {
val vals = iarray("789", "678", "567")
val diffs = ArrayList<Int>
for (i in vals.indices) {
for (j in i..vals.lastIndex()) // Type inference failed
diffs.add(vals[i].length - vals[j].length)
for (j in i..vals.lastIndex) // Type inference failed
diffs.add(vals[i].length - vals[j].length)
}
}
fun <T> Array<T>.lastIndex() = size - 1
val <T> Array<T>.lastIndex : Int get() = size - 1
@@ -0,0 +1,3 @@
//KT-571 Type inference failed
fun <T, R> let(t : T, body : fun(T) : R) = body(t)
private fun double(d : Int) : Int = let(d * 2) {it / 10 + it * 2 % 10}
@@ -1,6 +1,6 @@
fun typeName(a: Any?) : String {
return when(a) {
is java.util.ArrayList<Int> => "array list"
is java.util.ArrayList<*> => "array list"
else => "no idea"
}
}
@@ -8,4 +8,4 @@ fun typeName(a: Any?) : String {
fun box() : String {
if(typeName(java.util.ArrayList<Int> ()) != "array list") return "array list failed"
return "OK"
}
}
@@ -19,7 +19,7 @@ fun t3() {
fun t4() {
val e: E? = E()
System.out?.println(e?.foo() == e) //verify error
System.out?.println(e?.bar() == e) //verify error
System.out?.println(e?.foo()) //verify error
}
@@ -35,4 +35,5 @@ class C(val x: Int)
class D(val s: String)
class E() {
fun foo() = 1
fun bar() = this
}