Files
kotlin-fork/compiler/testData/codegen/box/callableReference/adaptedReferences/varargFromBaseClass.kt
T
Alexander Udalov dbd28142d0 Fix callable reference adaptation for vararg in fake override
`mappedVarargElements` are populated with parameters from
`argumentMapping`, which is computed using `ArgumentsToParametersMapper`
which calls `original` on all value parameters (see
ArgumentsToParametersMapper.kt:136).

So the code that adds empty lists for unassigned vararg parameters
should also call `original`. Otherwise, in the added test, we ended up
with two arguments for the parameter `s` in `id(::base1)`, one for
`Base.s` containing the correct value, and another for `Derived.s`
containing the empty list. Psi2ir took the last one, which resulted in
empty array being passed to the vararg parameter.

Note that all of this is caused by the fact that `original` of a fake
override parameter is the parameter of the base function. This seems
suspicious because `original` of a fake override _function_ is that fake
override itself (NOT the base function), but this would probably be very
risky to change at this point.

 #KT-48835 Fixed
2021-09-30 14:08:38 +02:00

43 lines
930 B
Kotlin
Vendored

var result = ""
abstract class Base {
fun base1(vararg s: String) {
if (s.size != 1) throw AssertionError("Fail size: ${s.size}")
result += s[0]
}
fun base2(s: String) {
result += s
}
}
fun id(f: (String) -> Unit): (String) -> Unit = f
class Derived : Base() {
init {
id { base1(it) }.invoke("1")
id(::base1).invoke("2")
id { base2(it) }.invoke("3")
id(::base2).invoke("4")
id { derived1(it) }.invoke("5")
id(::derived1).invoke("6")
id { derived2(it) }.invoke("7")
id(::derived2).invoke("8")
}
private fun derived1(vararg s: String) {
if (s.size != 1) throw AssertionError("Fail size: ${s.size}")
result += s[0]
}
private fun derived2(s: String) {
result += s
}
}
fun box(): String {
Derived()
return if (result == "12345678") "OK" else "Fail result: $result"
}