diff --git a/library/src/scala/runtime/EnumValues.scala b/library/src/scala/runtime/EnumValues.scala index 3f59faed5d56..b3f960b7f604 100644 --- a/library/src/scala/runtime/EnumValues.scala +++ b/library/src/scala/runtime/EnumValues.scala @@ -1,9 +1,9 @@ package scala.runtime -import scala.collection.immutable.Map +import scala.collection.immutable.TreeMap class EnumValues[E <: Enum] { - private[this] var myMap: Map[Int, E] = Map() + private[this] var myMap: Map[Int, E] = TreeMap.empty private[this] var fromNameCache: Map[String, E] = null def register(v: E) = { diff --git a/tests/run/enum-values-order.scala b/tests/run/enum-values-order.scala new file mode 100644 index 000000000000..be2b602f158c --- /dev/null +++ b/tests/run/enum-values-order.scala @@ -0,0 +1,8 @@ +/** immutable hashmaps (as of 2.13 collections) only store up to 4 entries in insertion order */ +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 } + +@main def Test = + import LatinAlphabet._ + 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) + + assert(ordered sameElements LatinAlphabet.values) diff --git a/tests/run/planets.check b/tests/run/planets.check index feb6f737db78..2785b93d3008 100644 --- a/tests/run/planets.check +++ b/tests/run/planets.check @@ -1,8 +1,8 @@ Your weight on MERCURY is 37.775761520093525 -Your weight on SATURN is 106.60155388115666 Your weight on VENUS is 90.49990998410455 -Your weight on URANUS is 90.51271993894251 Your weight on EARTH is 100.0 -Your weight on NEPTUNE is 113.83280724696579 Your weight on MARS is 37.873718403712886 Your weight on JUPITER is 253.05575254957407 +Your weight on SATURN is 106.60155388115666 +Your weight on URANUS is 90.51271993894251 +Your weight on NEPTUNE is 113.83280724696579