Files
kotlin-fork/compiler/testData/codegen/box/objects/useAnonymousObjectFunction.kt
T
Nikolay Lunyak a9343aeb7d [FIR] KT-55840: Ensure everything actually works
This inconsistency is present due to not using the `// WITH_STDLIB`
in the above tests. When K1 creates the enum, it tries to generate
`entries()`, and for that it tries to load `kotlin.enums.EnumEntries`,
but this is actually an unresolved reference. K1 silently swallows it,
and proceeds.

The reason K2 doesn't fail is that in order to generate `entries()` it
simply creates the necessary `ConeClassLikeType` with the desired
`classId` instead of loading the whole `ClassDescriptor`.

The reason we can still observe `$ENTRIES` and `$entries` in K1
is because they are generated during the JVM codegen, and it
only checks if the `EnumEntries` language feature is supported. It
doesn't check if the `entries` property has really existed in IR
(by this time it's expected to have already been lowered to the
`get-entries` function - that's why "has ... existed").

The reason why the codegen doesn't fail when working with
`kotlin.enums.EnumEntries` is because it creates its
own `IrClassSymbol`.

^KT-55840 Fixed

Merge-request: KT-MR-8727
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-10 16:57:51 +00:00

48 lines
897 B
Kotlin
Vendored

// WITH_STDLIB
// KT-44050
enum class Enum {
Entry1() {
fun bogus() = 42
},
Entry2() {
fun bogus() = 42
}
}
class Outer {
fun barCaller(): Enum = obj1.bar()
fun bazCaller(): Enum = obj2.baz()
private abstract inner class Inner<T>(val default: T) {
abstract fun foo()
}
private val obj1 = object : Inner<Enum>(Enum.Entry1) {
override fun foo() {
TODO("not related")
}
fun bar(): Enum {
return default
}
}
private val obj2 = object : Inner<Enum>(Enum.Entry2) {
override fun foo() {
TODO("not related")
}
fun baz(): Enum {
return default
}
}
}
fun box(): String {
val o = Outer()
if (o.barCaller() != Enum.Entry1) return "Fail1"
if (o.bazCaller() != Enum.Entry2) return "Fail2"
return "OK"
}