[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>
This commit is contained in:
Nikolay Lunyak
2023-02-10 16:57:51 +00:00
committed by Space Team
parent 57eae167cc
commit a9343aeb7d
207 changed files with 280 additions and 223 deletions
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A() {
ENTRY(){ override fun t() = "OK"};
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E {
ENTRY;
@@ -1,3 +1,4 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM
// FILE: Foo.java
@@ -1,3 +1,4 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM
// FILE: Foo.java
@@ -1,3 +1,4 @@
// WITH_STDLIB
// http://youtrack.jetbrains.com/issue/KT-2167
enum class Season {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
@@ -1,3 +1,4 @@
// WITH_STDLIB
private var logs = ""
enum class Foo(val text: String) {
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Game {
ROCK,
PAPER,
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS
fun f(): String = "O"
fun g(): String = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR
// K2 status: declaringClass is error for enums since Kotlin 1.9
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
X {
val x = "OK"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
X {
val k = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Test(val str: String = "OK") {
OK
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Test(vararg xs: Int) {
OK;
val values = xs
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Test(val str: String = "OK") {
OK {
fun foo() {}
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JS_IR, NATIVE
enum class Test {
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JS_IR, NATIVE
enum class Test(val x: Int, val str: String) {
OK;
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JS_IR, NATIVE
enum class Test(val x: Int, val str: String) {
OK;
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JS_IR, NATIVE
package test
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Empty
@@ -1,3 +1,4 @@
// WITH_STDLIB
// DONT_TARGET_EXACT_BACKEND: JS
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A(
name: String,
ordinal: Int
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface IFoo {
fun foo(): String
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface IFoo {
fun foo(): String
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface IFoo {
fun foo(): String
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
package test
fun box() = MyEnum.E1.f() + MyEnum.E2.f()
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Color(val rgb: Int) {
RED(0xff0000),
GREEN(0x00ff00),
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: WASM
enum class E { OK }
@@ -1,3 +1,4 @@
// WITH_STDLIB
// KT-4423 Enum with function not compiled
// SKIP_MANGLE_VERIFICATION
@@ -1,3 +1,4 @@
// WITH_STDLIB
package foo
enum class X {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
package test
enum class Season {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
fun box() = if(Context.operatingSystemType == Context.Companion.OsType.OTHER) "OK" else "fail"
public class Context
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS
var l = ""
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: WASM
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS
var l = ""
@@ -1,3 +1,4 @@
// WITH_STDLIB
// DONT_TARGET_EXACT_BACKEND: JS
// DONT_TARGET_EXACT_BACKEND: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS_IR_ES6
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
class A {
enum class E {
OK
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
X {
val x = "OK"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
X {
val x = "OK"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
X {
val x = "OK"
@@ -1,3 +1,4 @@
// WITH_STDLIB
class A {
companion object {}
enum class E {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Direction() {
NORTH {
val someSpecialValue = "OK"
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Bar {
ONE,
TWO
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
// SKIP_DCE_DRIVEN
enum class Bar {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Test(val x: String, val closure1: () -> String) {
FOO("O", { FOO.x }) {
override val y: String = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Test(val x: String, val closure1: () -> String) {
FOO("O", run { { FOO.x } }) {
override val y: String = "K"
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
// SKIP_MANGLE_VERIFICATION
enum class Foo(
val x: String,
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
// SKIP_MANGLE_VERIFICATION
interface Callback {
fun invoke(): String
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A(val b: String) {
E1("OK"){ override fun t() = b };
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E(val b: Boolean) {
TRUE(1 == 1)
}
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class ContentType {
PLAIN_TEXT {
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface IFoo {
fun foo(e: En): String
}
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
fun call(f: () -> Unit) {
f()
}
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
override val value = "OK"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
override val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
override val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
val value2 = "K"
@@ -1,3 +1,4 @@
// WITH_STDLIB
fun <T, R> T.letNoInline(fn: (T) -> R) =
fn(this)
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class X {
B {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class IssueState {
FIXED {
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class ClassTemplate(
// var bug: Int = 1,
var code: Int,
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class State {
_0,
_1,
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E {
A;
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Enum {
ENUM_VALUE {
override fun test() = ENUM_VALUE
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Season {
WINTER,
SPRING,
@@ -1,3 +1,4 @@
// WITH_STDLIB
package test
fun box() = E.E1.f() + E.E2.f()
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class State {
O,
K
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Color {
RED,
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E {
OK, NOT_OK
}