[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
// TARGET_BACKEND: JVM
enum class SomeEnum {
@@ -1,3 +1,4 @@
// WITH_STDLIB
// !LANGUAGE: +NestedClassesInAnnotations
annotation class Foo(val kind: Kind) {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface A<T> {
open fun foo(t: T) = "A"
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface A<T> {
open fun foo(t: T) = "A"
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: FUNCTION_REFERENCES
// IGNORE_BACKEND: JS, JS_IR
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E {
ENTRY
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
interface Named {
val name: String
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class E {
I
}
@@ -1,3 +1,4 @@
// WITH_STDLIB
import kotlin.reflect.KProperty1
class Q {
+1
View File
@@ -1,3 +1,4 @@
// WITH_STDLIB
package example2
fun box() = Context.OsType.OK.toString()
@@ -1,3 +1,4 @@
// WITH_STDLIB
abstract class Base(val fn: () -> Test)
enum class Test(val ok: String) {
@@ -1,3 +1,4 @@
// WITH_STDLIB
// MODULE: lib
// FILE: A.kt
@@ -1,3 +1,4 @@
// WITH_STDLIB
// MODULE: lib
// FILE: A.kt
@@ -1,3 +1,4 @@
// WITH_STDLIB
// MODULE: lib
// FILE: 1.kt
@@ -1,3 +1,4 @@
// WITH_STDLIB
// MODULE: lib
// FILE: A.kt
@@ -1,3 +1,4 @@
// WITH_STDLIB
// MODULE: lib
// FILE: A.kt
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A(val a: Int = 1) {
FIRST(),
SECOND(2)
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Foo(val a: Int = 1, val b: String) {
B(2, "b"),
C(b = "b")
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Foo(val a: Int = 1, val b: String = "a") {
A(),
B(2, "b"),
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class Foo(val a: Double = 1.0, val b: Double = 1.0) {
A(),
B(2.0, 2.0),
@@ -1,40 +0,0 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
private synthetic final static field $ENTRIES: kotlin.enums.EnumEntries
private synthetic final static field $VALUES: E[]
public final enum static field X: E
private synthetic final static method $entries(): E[]
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static @org.jetbrains.annotations.NotNull method getEntries(): kotlin.enums.EnumEntries
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndImportFromObjectKt {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
private final static @org.jetbrains.annotations.NotNull field result$delegate: Delegate
static method <clinit>(): void
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getResult(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndImportFromObject.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -15,6 +15,7 @@ public final enum class E {
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static @org.jetbrains.annotations.NotNull method getEntries(): kotlin.enums.EnumEntries
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@@ -1,4 +1,5 @@
// CHECK_BYTECODE_LISTING
// WITH_STDLIB
import O.d
@@ -1,39 +0,0 @@
@kotlin.Metadata
public final class Delegate {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): java.lang.String
}
@kotlin.Metadata
public final enum class E {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
private synthetic final static field $ENTRIES: kotlin.enums.EnumEntries
private synthetic final static field $VALUES: E[]
public final enum static field X: E
private synthetic final static method $entries(): E[]
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static @org.jetbrains.annotations.NotNull method getEntries(): kotlin.enums.EnumEntries
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@kotlin.Metadata
public final class MemberExtensionPropertyAndLocalDelegatedPropertyKt {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[]
static method <clinit>(): void
private final static method box$lambda$1$lambda$0(p0: Delegate): java.lang.String
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@kotlin.Metadata
public final class O {
// source: 'memberExtensionPropertyAndLocalDelegatedProperty.kt'
public final static @org.jetbrains.annotations.NotNull field INSTANCE: O
static method <clinit>(): void
private method <init>(): void
public final @org.jetbrains.annotations.NotNull method getD(@org.jetbrains.annotations.NotNull p0: E): Delegate
}
@@ -15,6 +15,7 @@ public final enum class E {
private synthetic final static method $values(): E[]
static method <clinit>(): void
private method <init>(p0: java.lang.String, p1: int): void
public static @org.jetbrains.annotations.NotNull method getEntries(): kotlin.enums.EnumEntries
public static method valueOf(p0: java.lang.String): E
public static method values(): E[]
}
@@ -1,4 +1,5 @@
// CHECK_BYTECODE_LISTING
// WITH_STDLIB
enum class E { X }
@@ -1,3 +1,4 @@
// WITH_STDLIB
// IGNORE_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
ONE,
TWO;
@@ -1,3 +1,4 @@
// WITH_STDLIB
enum class A {
ONE,
TWO
@@ -1,3 +1,4 @@
// WITH_STDLIB
import A.ONE
enum class A {
@@ -1,3 +1,4 @@
// WITH_STDLIB
import A.ONE
enum class A {
@@ -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;

Some files were not shown because too many files have changed in this diff Show More