KT-353 Generic type argument inference sometimes doesn't work

KT-459 Type argument inference fails when class names are fully qualified
This commit is contained in:
Andrey Breslav
2011-11-09 22:15:37 +03:00
parent 8ab1f1b420
commit c6f6f182b6
3 changed files with 47 additions and 8 deletions
@@ -0,0 +1,8 @@
// KT-459 Type argument inference fails when class names are fully qualified
fun test() {
val attributes : java.util.HashMap<String, String> = java.util.HashMap() // failure!
attributes["href"] = "1" // inference fails, but it shouldn't
}
fun <K, V> java.util.Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
@@ -0,0 +1,32 @@
// KT-353 Generic type argument inference sometimes doesn't work
trait A {
fun <T> gen() : T
}
fun foo(a: A) {
val g : fun() : Unit = {
a.gen() //it works: Unit is derived
}
val u: Unit = a.gen() //type mismatch, but Unit can be derived
if (true) {
a.gen() //it works: Unit is derived
}
val b : fun() : Unit = {
if (true) {
a.gen() //type mismatch, but Unit can be derived
}
else {
()
}
}
val f : fun() : Int = { () : Int =>
a.gen() //type mismatch, but Int can be derived
}
a.gen() //it works: Unit is derived
}