Init enum entries whenever we access companion object or accessing valueOf

Fixes https://youtrack.jetbrains.com/issue/KT-43987
Fixes https://youtrack.jetbrains.com/issue/KT-43989
This commit is contained in:
Shagen Ogandzhanian
2020-12-30 14:52:21 +01:00
parent 7fa04afda2
commit e7dc199ad7
14 changed files with 284 additions and 18 deletions
@@ -0,0 +1,53 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: WASM
var l = ""
enum class Foo {
FOO,
BAR;
init {
l += "Foo.$name;"
}
companion object {
init {
l += "Foo.CO;"
}
val boo = 22
}
}
enum class Foo2 {
FOO,
BAR;
init {
l += "Foo2.$name;"
}
companion object {
init {
l += "Foo2.CO;"
}
val boo = 22
}
}
fun box(): String {
try {
Foo.valueOf("NO")
} catch (e: Throwable) {
l += "caught;"
}
if (l != "Foo.FOO;Foo.BAR;Foo.CO;caught;") return "Failure 0: l = $l"
l = ""
Foo2.valueOf("BAR")
if (l != "Foo2.FOO;Foo2.BAR;Foo2.CO;") return "Failure 1: l = $l"
return "OK"
}