[NI] Handle vararg parameter in reflection type wrt array types

Vararg parameter in reflection type is interpreted as covariant
array type against array in expected functional type and as
vararg element type otherwise. For instance having function
fun foo(vararg args: Int): Unit { /*...*/ }
reference ::foo can be passed against expected
(Int) -> Unit,
(Int, Int) -> Unit, etc.
In none of such cases type for parameter in foo's reflection type
should be changed to array.
However, against expected type (IntArray) -> Unit args' type
must become IntArray.

^KT-25514 Fixed
This commit is contained in:
Pavel Kirpichenkov
2019-11-19 19:14:45 +03:00
parent aba5ff0c1e
commit f80a71517f
13 changed files with 173 additions and 8 deletions
@@ -0,0 +1,28 @@
// !LANGUAGE: +NewInference
// DONT_RUN_GENERATED_CODE: JS
fun sum(vararg args: Int): Int {
var result = 0
for (arg in args)
result += arg
return result
}
fun nsum(vararg args: Number) = sum(*IntArray(args.size) { args[it].toInt() })
fun usePlainArgs(fn: (Int, Int) -> Int) = fn(1, 1)
fun usePrimitiveArray(fn: (IntArray) -> Int) = fn(intArrayOf(1, 1, 1))
fun useArray(fn: (Array<Int>) -> Int) = fn(arrayOf(1, 1, 1, 1))
fun box(): String {
var result = usePlainArgs(::sum)
if (result != 2)
return "Fail: plain args $result != 2"
result = usePrimitiveArray(::sum)
if (result != 3)
return "Fail: primitive array $result != 3"
result = useArray(::nsum)
if (result != 4)
return "Fail: reference array $result != 4"
return "OK"
}