[FE] Always infer upper types to intersection types in K2...

...and always use old algorithm for K1

^KT-51221
This commit is contained in:
Dmitriy Novozhilov
2022-11-28 17:54:55 +02:00
committed by Space Team
parent d50c072af0
commit ac7fddaad5
15 changed files with 42 additions and 25 deletions
@@ -2,7 +2,7 @@ package c
import java.util.ArrayList
fun Array<Int>.toIntArray(): IntArray = <!RETURN_TYPE_MISMATCH!>this.mapTo(<!ARGUMENT_TYPE_MISMATCH!>IntArray(size)<!>, {it})<!>
fun Array<Int>.toIntArray(): IntArray = this.mapTo(<!ARGUMENT_TYPE_MISMATCH!>IntArray(size)<!>, {it})
fun Array<Int>.toArrayList(): ArrayList<Int> = this.mapTo(ArrayList<Int>(size), {it})
@@ -1,3 +1,10 @@
/kt45461_25.kt:11:34: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K, Float (multiple incompatible classes: String, Int)
/kt45461_25.kt:11:20: error: type mismatch: inferred type is {K & String} but Float was expected
val x: Float = Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
/kt45461_25.kt:11:34: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: String, K (multiple incompatible classes: String, Int)
val x: Float = Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
/kt45461_25.kt:11:34: error: type mismatch: inferred type is {K & String} but Float was expected
val x: Float = Bar<String>().takeFoo(foo) // error in 1.3.72, no error in 1.4.31
^
@@ -8,5 +8,5 @@ class Bar<T> {
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Int<!>> main() {
val foo = Foo<K>()
val x: Float = Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; String, K, Float; multiple incompatible classes; : String, Int")!>takeFoo<!>(foo) // error in 1.3.72, no error in 1.4.31
val x: Float = <!TYPE_MISMATCH!>Bar<String>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; String, K; multiple incompatible classes; : String, Int"), TYPE_MISMATCH!>takeFoo<!>(foo)<!> // error in 1.3.72, no error in 1.4.31
}
@@ -1,4 +1,10 @@
/kt45461_26.kt:13:44: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: Out<String>, K, Out<Float> (multiple incompatible classes: String, Int)
/kt45461_26.kt:13:25: error: type mismatch: inferred type is {K & Out<String>} but Out<Float> was expected
val x: Out<Float> = Bar<Out<String>>().takeFoo(foo)
^
/kt45461_26.kt:13:44: error: type argument for a type parameter S can't be inferred because it has incompatible upper bounds: Out<String>, K (multiple incompatible classes: String, Int)
val x: Out<Float> = Bar<Out<String>>().takeFoo(foo)
^
/kt45461_26.kt:13:44: error: type mismatch: inferred type is {K & Out<String>} but Out<Float> was expected
val x: Out<Float> = Bar<Out<String>>().takeFoo(foo)
^
@@ -10,5 +10,5 @@ class Out<out K>
fun <K : L, L : N, N: <!FINAL_UPPER_BOUND!>Out<Int><!>> main() {
val foo = Foo<K>()
val x: Out<Float> = Bar<Out<String>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; Out<String>, K, Out<Float>; multiple incompatible classes; : String, Int")!>takeFoo<!>(foo)
val x: Out<Float> = <!TYPE_MISMATCH!>Bar<Out<String>>().<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR("S; Out<String>, K; multiple incompatible classes; : String, Int"), TYPE_MISMATCH!>takeFoo<!>(foo)<!>
}
@@ -11,7 +11,7 @@ fun test(x: X<Number>) {
fun <S, D: S> g() {
fun <T : S> foo(): T = TODO()
val y = <!NEW_INFERENCE_ERROR!>foo()<!> as Int
val y = <!DEBUG_INFO_EXPRESSION_TYPE("S!! & kotlin.Int")!>foo()<!> as Int
val y2 = foo() as D
}