diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 0fa1828e0aa..fb166d3c38b 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -516,6 +516,11 @@ task hello4(type: RunKonanTest) { source = "runtime/basic/hello4.kt" } +task enumEquals(type: RunKonanTest) { + goldValue = "true\nfalse\nfalse\n" + source = "runtime/basic/enum_equals.kt" +} + task entry0(type: RunStandaloneKonanTest) { goldValue = "Hello.\n" source = "runtime/basic/entry0.kt" @@ -658,6 +663,12 @@ task freeze_stress(type: RunKonanTest) { source = "runtime/workers/freeze_stress.kt" } +task enumIdentity(type: RunKonanTest) { + disabled = (project.testTarget == 'wasm32') // Workers need pthreads. + goldValue = "true\n" + source = "runtime/workers/enum_identity.kt" +} + task superFunCall(type: RunKonanTest) { goldValue = "\n\n" source = "codegen/basics/superFunCall.kt" diff --git a/backend.native/tests/runtime/basic/enum_equals.kt b/backend.native/tests/runtime/basic/enum_equals.kt new file mode 100644 index 00000000000..5ec24e08719 --- /dev/null +++ b/backend.native/tests/runtime/basic/enum_equals.kt @@ -0,0 +1,17 @@ +package runtime.basic.enum_equals + +import kotlin.test.* + +enum class EnumA { + A, B +} + +enum class EnumB { + B +} + +@Test fun run() { + println(EnumA.A == EnumA.A) + println(EnumA.A == EnumA.B) + println(EnumA.A == EnumB.B) +} \ No newline at end of file diff --git a/backend.native/tests/runtime/workers/enum_identity.kt b/backend.native/tests/runtime/workers/enum_identity.kt new file mode 100644 index 00000000000..233b4bebc26 --- /dev/null +++ b/backend.native/tests/runtime/workers/enum_identity.kt @@ -0,0 +1,19 @@ +package runtime.workers.enum_identity + +import kotlin.test.* +import konan.worker.* + +enum class A { + A, B +} + +data class Foo(val kind: A) + +// Enums are shared between threads so identity should be kept. +@Test +fun runTest() { + val result = startWorker().schedule(TransferMode.CHECKED, { Foo(A.B) }, { input -> + input.kind == A.B + }).result() + println(result) +} \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/Enum.kt b/runtime/src/main/kotlin/kotlin/Enum.kt index bb0164ac982..0bc4c519ae1 100644 --- a/runtime/src/main/kotlin/kotlin/Enum.kt +++ b/runtime/src/main/kotlin/kotlin/Enum.kt @@ -36,7 +36,7 @@ public abstract class Enum>(public val name: String, public val ordin } public override final fun equals(other: Any?): Boolean { - return other is Enum<*> && ordinal == other.ordinal + return this === other } public override final fun hashCode(): Int {