We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The following code worked fine with Scala 2.7.x but now crashes at runtime with Scala 2.8.x :
object test { object State extends Enumeration { val UNKNOWN = Value(-3, "UNKNOWN") val WIN = Value(-2, "WIN") val EMPTY = Value( 0, "EMPTY") val PLAYER1 = Value( 1, "PLAYER1") val PLAYER2 = Value( 2, "PLAYER2") // 2.7.x // def fromInt(id: Int) = elements find (_.id == id) match { // 2.8.x def fromInt(id: Int) = values find (_.id == id) match { case Some(v) => v case None => UNKNOWN } } def main(args: Array[String]) { println(State.fromInt(-2)) // 2.7.x ==> WIN // 2.8.x ==> java.lang.IllegalArgumentException: // requirement failed: bitset element must be >= 0 } }
The original Java 1.5 code (cf. android-sdk/TicTacToeMain/) is:
class test { public enum State { UNKNOWN(-3), WIN(-2), EMPTY(0), PLAYER1(1), PLAYER2(2); private int mValue; private State(int value) { mValue = value; } public int getValue() { return mValue; } public static State fromInt(int i) { for (State s : values()) { if (s.getValue() == i) { return s; } } return EMPTY; } } public static void main(String[] args) { System.out.println(State.fromInt(-2)); // ==> WIN } }
The text was updated successfully, but these errors were encountered:
Imported From: https://issues.scala-lang.org/browse/SI-3950?orig=1 Reporter: @michelou See #5211
Sorry, something went wrong.
@odersky said: Did the code work in 2.8.0?
@paulp said: Replying to [comment:1 odersky]:
Did the code work in 2.8.0?
It does not work in 2.8.0.
@hubertp said: Actually, I will take it since the previous enumeration bugs are also assigned to me
@hubertp said: (In r23893) Closes #3687, #3719, #3950, #3616. Plus removed some deprecated stuff for 2.9. Review by extempore
hubertp
No branches or pull requests
The following code worked fine with Scala 2.7.x but now crashes at runtime with Scala 2.8.x :
The original Java 1.5 code (cf. android-sdk/TicTacToeMain/) is:
The text was updated successfully, but these errors were encountered: