Files
kotlin-fork/compiler/testData/codegen/box/defaultArguments/function/kt15971.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

19 lines
313 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
interface Q {
fun foo(a: Double): Double
}
interface Z {
fun foo(a: Double = 1.0): Double
}
class R : Q, Z {
override fun foo(a: Double) = a
}
fun box(): String {
if (R().foo() != 1.0) return "fail 1"
if (R().foo(2.0) != 2.0) return "fail 2"
return "OK"
}