Skip to content

Commit fa0ffc0

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

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

library/src/scala/runtime/EnumValues.scala

+2-2
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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** immutable hashmaps (as of 2.13 collections) only store up to 4 entries in insertion order */
2+
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 }
3+
4+
@main def Test =
5+
import LatinAlphabet._
6+
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)
7+
8+
assert(ordered sameElements LatinAlphabet.values)

0 commit comments

Comments
 (0)