Skip to content

fix #6663: sort EnumValues by ordinal #9524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/src/scala/runtime/EnumValues.scala
Original file line number Diff line number Diff line change
@@ -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) = {
Expand Down
8 changes: 8 additions & 0 deletions tests/run/enum-values-order.scala
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions tests/run/planets.check
Original file line number Diff line number Diff line change
@@ -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