fixed bug in constraint system

For parameter type T constraint T? <: Int? should NOT transform to T <: Int, it should be T <: Int?
equality constraint T? = Int? should transform to T <: Int? && T >: Int
This commit is contained in:
Svetlana Isakova
2013-09-19 17:23:34 +04:00
parent d4aaed2787
commit 9a0ec7949e
7 changed files with 152 additions and 5 deletions
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: -BASE_WITH_NULLABLE_UPPER_BOUND
class TypeOf<T>(t: T)
trait A<T>
fun <T> foo(a: A<T>, aN: A<T?>): T = throw Exception("$a $aN")
fun <T> doA(a: A<T>): T = throw Exception("$a")
fun test(a: A<Int>, aN: A<Int?>) {
val aa = doA(aN)
TypeOf(aa): TypeOf<Int?>
val nullable = foo(aN, aN)
//T = Int?, T? = Int? => T = Int?
TypeOf(nullable): TypeOf<Int?>
val notNullable = foo(a, aN)
//T = Int, T? = Int? => T = Int
TypeOf(notNullable): TypeOf<Int>
}
@@ -0,0 +1,25 @@
class TypeOf<T>(t: T)
trait A<T>
trait In<in T>
trait Out<out T>
fun <T: Any> doT(t: T?): T = throw Exception("$t")
fun <T: Any> doOut(o: Out<T?>): T { throw Exception("$o") }
fun <T: Any> doIn(i: In<T?>) { throw Exception("$i") }
fun <T: Any> doA(i: A<T?>) { throw Exception("$i") }
fun test(out: Out<Int>, i: In<Int>, inv: A<Int>) {
// T? >: Int => T = Int
doT(1)
val r = doOut(out)
TypeOf(r): TypeOf<Int>
// T? <: Int => error
doIn(<!TYPE_MISMATCH!>i<!>)
// T? >: Int => error
doA(<!TYPE_MISMATCH!>inv<!>)
}
@@ -0,0 +1,24 @@
// !DIAGNOSTICS: -BASE_WITH_NULLABLE_UPPER_BOUND
class TypeOf<T>(t: T)
trait A<T>
trait Out<out T>
fun <T> foo(a: A<T>, o: Out<T?>): T = throw Exception("$a $o")
fun <T> doOut(o: Out<T?>): T = throw Exception("$o")
fun test(a: A<Int>, aN: A<Int?>, o: Out<Int?>) {
val out = doOut(o)
//T? >: Int? => T >: Int
TypeOf(out): TypeOf<Int>
val nullable = foo(aN, o)
//T = Int?, T? >: Int? => T = Int?
TypeOf(nullable): TypeOf<Int?>
val notNullable = foo(a, o)
//T = Int, T? >: Int? => T = Int
TypeOf(notNullable): TypeOf<Int>
}
@@ -0,0 +1,24 @@
// !DIAGNOSTICS: -BASE_WITH_NULLABLE_UPPER_BOUND
class TypeOf<T>(t: T)
trait A<T>
trait In<in T>
fun <T> foo(a: A<T>, i: In<T>): T = throw Exception("$a $i")
fun <T> doIn(i: In<T?>): T = throw Exception("$i")
fun test(a: A<Int>, aN: A<Int?>, i: In<Int?>) {
val _in = doIn(i)
//T? <: Int? => T <: Int?
TypeOf(_in): TypeOf<Int?>
val notNullable = foo(a, i)
//T = Int, T? <: Int? => T = Int
TypeOf(notNullable): TypeOf<Int>
val nullable = foo(aN, i)
//T = Int?, T? <: Int? => T = Int?
TypeOf(nullable): TypeOf<Int?>
}