Skip to content
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

Enum with duplicate ordinal throws AssertionError without additional information #3615

Closed
scabug opened this issue Jun 28, 2010 · 5 comments
Closed
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jun 28, 2010

object WeekDay extends Enumeration {
     type WeekDay = Value
     val Mon = Value(1)
     val Tue = Value(1)
}

WeekDay.Mon.id

java.lang.AssertionError: assertion failed
        at scala.Predef$$.assert(Predef.scala:78)
        at scala.Enumeration$$Val.<init>(Enumeration.scala:266)
        at scala.Enumeration.Value(Enumeration.scala:175)
        at WeekDay$$.<init>(<console>:8)
        at WeekDay$$.<clinit>(<console>)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
@scabug
Copy link
Author

scabug commented Jun 28, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3615?orig=1
Reporter: Thomas Jung (thomas jung)
See #5211

@scabug
Copy link
Author

scabug commented Jun 29, 2010

@dragos said:
And what behavior would you expect? You are breaking an invariant, so I believe an error is in place, and I don't think this is a recoverable error. The program is simply broken and needs to be fixed.

@scabug
Copy link
Author

scabug commented Jun 29, 2010

@harrah said:
I think the request is simply for a message to go with the assert. Line 266 of Enumeration.scala could be changed to:

assert(!vmap.isDefinedAt(i), "Duplicate id: " + i)

@scabug
Copy link
Author

scabug commented Jun 29, 2010

Thomas Jung (thomas jung) said:
Yes, I expected a hint of what's the cause of this problem.

@scabug
Copy link
Author

scabug commented Jun 30, 2010

@paulp said:
(In r22446) Enumeration fixes. There was no way to do reflection-based naming
correctly simply by inspecting method signatures (because a Value from
a different Enumeration stored in a val looks identical to one from
this Enumeration) so I have Value store the outer Enum for comparison
purposes. This won't make anything new uncollectable because they
already have an $$outer pointing there. This also simplified the
reflection logic: it's an eq test rather than a series of heuristics.

Closes #3616, #3615. Review by phaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant