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

for a in MyEnum gives incorrect results with enum with holes #14001

Closed
timotheecour opened this issue Apr 16, 2020 · 2 comments
Closed

for a in MyEnum gives incorrect results with enum with holes #14001

timotheecour opened this issue Apr 16, 2020 · 2 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Apr 16, 2020

for a in MyEnum gives incorrect results with enum with holes.

Before you say

Yeah, enums with holes are simply madness. We should deprecate them for 1.4.

they still have valid use cases for interop (a necessary evil) and all existing alternatives (const + distinct cint or holyEnum #13980 (comment)) have their own caveats, and in any case, we still need to support them for backward compatibility.

The fix is not hard, it's done by something similar (and simpler!) to the magic iterators.fields.

Example

when true: # D20200416T162309
  type Foo = enum
    f1 = -1, f2 = 13, f3 = 20
  for ai in Foo: echo ai

Current Output

f1
0 (invalid data!)
f2
f3

Expected Output

f1
f2
f3

Possible Solution

  • create a magic enumItems similar to iterators.fields

Additional Information

@alaviss
Copy link
Collaborator

alaviss commented Apr 17, 2020

We can just ban this for enum with holes.

A wide range of operations should be banned for them too (like inc, dec). They aren't ordinals and shouldn't be treated like one.

@Araq
Copy link
Member

Araq commented Apr 17, 2020

Precisely what @alaviss said.

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

Successfully merging a pull request may close this issue.

3 participants