KT-702 Type inference failed

This commit is contained in:
Andrey Breslav
2011-12-01 22:33:43 +03:00
parent df733a5b60
commit 13a1777d39
8 changed files with 259 additions and 167 deletions
@@ -4,7 +4,7 @@ fun <T> Array<out T>.safeGet(index : Int) : T? {
return if (index < size) this[index] else null
}
val args : Array<String> = Array<String>(1)
val args : Array<String> = Array<String>(1, {""})
val name : String = <!TYPE_MISMATCH!>args.safeGet<String>(0)<!> // No error, must be type mismatch
val name1 : String? = args.safeGet(0)
@@ -0,0 +1,18 @@
// KT-702 Type inference failed
// +JDK
fun getJavaClass<T>() : java.lang.Class<T> { return "" <!CAST_NEVER_SUCCEEDS!>as<!> Class<T> }
public class Throwables() {
class object {
public fun propagateIfInstanceOf<X : Throwable?>(throwable : Throwable?, declaredType : Class<X?>?) {
if (((throwable != null) && declaredType?.isInstance(throwable).sure()))
{
throw declaredType?.cast(throwable)
}
}
public fun propagateIfPossible(throwable : Throwable?) {
propagateIfInstanceOf(throwable, getJavaClass<Error?>) //; Type inference failed: Mismatch while expanding constraints
propagateIfInstanceOf(throwable, getJavaClass<RuntimeException?>) // Type inference failed: Mismatch while expanding constraints
}
}
}