Skip to content

Commit daf769b

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

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
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)

tests/run/planets.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Your weight on MERCURY is 37.775761520093525
2-
Your weight on SATURN is 106.60155388115666
32
Your weight on VENUS is 90.49990998410455
4-
Your weight on URANUS is 90.51271993894251
53
Your weight on EARTH is 100.0
6-
Your weight on NEPTUNE is 113.83280724696579
74
Your weight on MARS is 37.873718403712886
85
Your weight on JUPITER is 253.05575254957407
6+
Your weight on SATURN is 106.60155388115666
7+
Your weight on URANUS is 90.51271993894251
8+
Your weight on NEPTUNE is 113.83280724696579

0 commit comments

Comments
 (0)