[JS IR BE] Support enumValues<T>() and enumValueOf<T>(name)
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
public class Enum<E : Enum<E>>(val name: String, val ordinal: Int) : Comparable<E> {
|
||||
import kotlin.js.*
|
||||
|
||||
abstract class Enum<E : Enum<E>>(val name: String, val ordinal: Int) : Comparable<E> {
|
||||
|
||||
override fun compareTo(other: E) = ordinal.compareTo(other.ordinal)
|
||||
|
||||
@@ -16,4 +18,14 @@ public class Enum<E : Enum<E>>(val name: String, val ordinal: Int) : Comparable<
|
||||
override fun toString() = name
|
||||
|
||||
companion object
|
||||
}
|
||||
}
|
||||
|
||||
// Use non-inline calls to enumValuesIntrinsic and enumValueOfIntrinsic calls in order
|
||||
// for compiler to replace them with method calls of concrete enum classes after inlining.
|
||||
// TODO: Figure out better solution (Inline hacks? Dynamic calls to stable mangled names?)
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <reified T : Enum<T>> enumValues(): Array<T> = enumValuesIntrinsic<T>()
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
public inline fun <reified T : Enum<T>> enumValueOf(name: String): T = enumValueOfIntrinsic<T>(name)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.js
|
||||
|
||||
@PublishedApi
|
||||
internal fun <T : Enum<T>> enumValuesIntrinsic(): Array<T> =
|
||||
throw IllegalStateException("Should be replaced by compiler")
|
||||
|
||||
@PublishedApi
|
||||
internal fun <T : Enum<T>> enumValueOfIntrinsic(name: String): T =
|
||||
throw IllegalStateException("Should be replaced by compiler")
|
||||
Reference in New Issue
Block a user