Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM, JVM_IR, NATIVE
// IGNORE_BACKEND: JVM, JVM_IR

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM_IR, NATIVE
// IGNORE_BACKEND: JVM_IR

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: NATIVE

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM, JVM_IR, NATIVE
// IGNORE_BACKEND: JVM, JVM_IR

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: NATIVE

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM_IR, NATIVE
// IGNORE_BACKEND: JVM_IR

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM_IR, NATIVE
// IGNORE_BACKEND: JVM_IR

// This test is essentially the same one as initializersInheritanceMultipleSupertypes,
// but with different super type kinds order (interface, class, interface)
Expand Down Expand Up @@ -59,11 +59,11 @@ fun box(): String {
if (Foo.fooProp2 != "foo2") return "FAIL: fooProp2=${Foo.fooProp2}"

// Order: superclass, then superinterfaces (declaration order), then Foo itself.
if (initOrder != "IF2 BAR1 BAR2 IF1 FOO1 FOO2 ") return "FAIL: initOrder=$initOrder"
if (initOrder != "BAR1 BAR2 IF2 IF1 FOO1 FOO2 ") return "FAIL: initOrder=$initOrder"

// Accessing companion members again must not re-run any initializer.
if (Foo.fooProp2 != "foo2") return "FAIL: fooProp2 (second access)=${Foo.fooProp2}"
if (initOrder != "IF2 BAR1 BAR2 IF1 FOO1 FOO2 ") return "FAIL: initOrder after re-access=$initOrder"
if (initOrder != "BAR1 BAR2 IF2 IF1 FOO1 FOO2 ") return "FAIL: initOrder after re-access=$initOrder"

return "OK"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LANGUAGE: +CompanionBlocksAndExtensions
// IGNORE_BACKEND: JVM, JVM_IR, NATIVE
// IGNORE_BACKEND: JVM, JVM_IR

var initOrder = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ISSUE: KT-86521 Native: init order of companion objects is different from JVM
// IGNORE_BACKEND: NATIVE
// ^ On Native `CompanionBlocksAndExtensions` language feature enables the JVM-like initialization.
// See nativeCompanionInitOrderCrossModule* tests for Native-specific treatment.
// ISSUE: KT-84267 K/Wasm: init order of companion objects is different from JVM
// ISSUE: KT-86640 K/Wasm: cross-module signature mismatch for parent companion getInstance
// IGNORE_KLIB_RUNTIME_ERRORS_WITH_CUSTOM_SECOND_STAGE: Wasm-js:2.3,2.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ISSUE: KT-86521 Native: init order of companion objects is different from JVM
// IGNORE_BACKEND: NATIVE
// ^ On Native `CompanionBlocksAndExtensions` language feature enables the JVM-like initialization.
// See nativeCompanionInitOrder* tests for Native-specific treatment.
// ISSUE: KT-84267 K/Wasm: init order of companion objects is different from JVM
// IGNORE_KLIB_RUNTIME_ERRORS_WITH_CUSTOM_SECOND_STAGE: Wasm-js:2.3,2.4
// ^^^KT-84267 is fixed in 2.4.20-beta1
Expand Down Expand Up @@ -189,6 +191,62 @@ class A16 : B16<String>() {
companion object { init { log("A16.Companion") } }
}

// multiple interface inheritance
interface I17 {
fun i() {}
companion object { init { log("I17.Companion") } }
}
interface J17 {
fun j() {}
companion object { init { log("J17.Companion") } }
}
interface K17 : I17 {
fun k() {}
companion object { init { log("K17.Companion") } }
}
interface L17 : J17 {
fun l() {}
companion object { init { log("L17.Companion") } }
}
interface M17 {
companion object { init { log("M17.Companion") } }
}
open class B17 : J17, K17 {
companion object { init { log("B17.Companion") } }
}
class A17: B17(), L17, M17 {
companion object { init { log("A17.Companion") } }
}

// multiple interface inheritance; with instance creation
interface I18 {
fun i() {}
companion object { init { log("I18.Companion") } }
}
interface J18 {
fun j() {}
companion object { init { log("J18.Companion") } }
}
interface K18 : I18 {
fun k() {}
companion object { init { log("K18.Companion") } }
}
interface L18 : J18 {
fun l() {}
companion object { init { log("L18.Companion") } }
}
interface M18 {
companion object { init { log("M18.Companion") } }
}
open class B18 : J18, K18 {
init { log("B18.init") }
companion object { init { log("B18.Companion") } }
}
class A18: B18(), L18, M18 {
init { log("A18.init") }
companion object { init { log("A18.Companion") } }
}

fun box(): String {
l = ""
A1
Expand Down Expand Up @@ -279,5 +337,15 @@ fun box(): String {
val r16 = l
if (r16 != "B16.Companion\nA16.Companion\n") return "fail test16: '$r16'"

l = ""
A17
val r17 = l
if (r17 != "J17.Companion\nI17.Companion\nK17.Companion\nB17.Companion\nL17.Companion\nA17.Companion\n") return "fail test17: '$r17'"

l = ""
A18()
val r18 = l
if (r18 != "J18.Companion\nI18.Companion\nK18.Companion\nB18.Companion\nL18.Companion\nA18.Companion\nB18.init\nA18.init\n") return "fail test18: '$r18'"

return "OK"
}
Loading