mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-12 15:53:40 +00:00
If a class inherits from another class which captures something (outer class instance, receiver parameter, local variables, etc.), the constructor of the former class should contain all the parameters of the super constructor as its own parameters, so that it could make a proper super call. All such parameters are now replicated in the derived constructor with kind = SUPER_CALL_PARAM, except an instance of the outer class (kind = OUTER), which can be taken from the derived's own OUTER when it has one, to prevent multiple passing of the same argument. Previously it worked only when inheriting from inner classes via a special hack (ConstructorFrameMap). Also reuse recently introduced ArgumentGenerator to automatically take care of default and vararg arguments of super constructor #KT-3581 Fixed #KT-5342 Fixed #KT-5343 Fixed
15 lines
593 B
Kotlin
15 lines
593 B
Kotlin
// When inner class extends its outer, there are two instances of the outer present in the inner:
|
|
// the enclosing one and the one in the super call.
|
|
// Here we test that symbols are resolved to the instance created via the super call.
|
|
// This differs from Java, so this test may change when we revisit code generation of inner classes
|
|
|
|
open class Outer(vararg val chars: Char) {
|
|
open inner class Inner(val s: String): Outer(s[0], s[1]) {
|
|
fun concat() = java.lang.String.valueOf(chars)
|
|
}
|
|
|
|
fun value() = Inner("OK").concat()
|
|
}
|
|
|
|
fun box() = Outer('F', 'a', 'i', 'l').value()
|