Files
kotlin-fork/compiler/testData/codegen/box/defaultArguments/implementedByFake.kt
T
Dmitry Petrov 2f82c5b6af JVM: Fix default parameter values handling
When we generate call for 'foo', we make decision about invoking
a 'foo$default' too late, after the call arguments are generated.
If 'foo' was an override, and base class (interface) was generic,
'foo' in base class could have a different Kotlin and JVM
signature, so the arguments we generated could be generated wrong
(primitive or inline class values instead of boxes, see KT-38680).
Also, we always selected first base class in supertypes list,
which caused KT-15971.

Look into resolved call and see if we should actually call
'foo$default' instead of 'foo' when determining actual callable.

Overrides can't introduce default parameter values, and
override-equivalent inherited methods with default parameters
is an error in a child class. Thus, if we are calling a class
member function with a default parameters, there should be one
and only one overridden function that has default parameter values
and overrides nothing.
2020-05-20 07:19:29 +03:00

40 lines
729 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
interface I<T> {
val prop: T
fun f(x: String = "1"): String
fun g(x: String = "2"): String
fun h(x: T = prop): T
}
open class A<T> {
open fun f(x: String) = x
open fun g(x: T) = x
open fun h(x: String) = x
}
class B : A<String>(), I<String> {
override val prop
get() = "3"
}
fun box(): String {
val i: I<String> = B()
var result = i.f() + i.g() + i.h()
if (result != "123") return "fail1: $result"
val b = B()
result = b.f() + b.g() + b.h()
if (result != "123") return "fail2: $result"
val a: A<String> = B()
result = a.f("q") + a.g("w") + a.h("e")
if (result != "qwe") return "fail3: $result"
return "OK"
}