Skip to content

Commit 9d40d3e

Browse files
committed
fix #6663: sort EnumValues by ordinal
1 parent 493f192 commit 9d40d3e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

library/src/scala/runtime/EnumValues.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package scala.runtime
22

3-
import scala.collection.immutable.Map
3+
import scala.collection.immutable.TreeMap
44

55
class EnumValues[E <: Enum] {
6-
private[this] var myMap: Map[Int, E] = Map()
6+
private[this] var myMap: Map[Int, E] = TreeMap.empty
77
private[this] var fromNameCache: Map[String, E] = null
88

99
def register(v: E) = {

tests/run/enum-values-order.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum LatinAlphabet { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }
2+
3+
@main def Test =
4+
import LatinAlphabet._
5+
val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)
6+
7+
assert(ordered sameElements LatinAlphabet.values)

0 commit comments

Comments
 (0)