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

allow when in enum types #190

Closed
timotheecour opened this issue Feb 6, 2020 · 5 comments
Closed

allow when in enum types #190

timotheecour opened this issue Feb 6, 2020 · 5 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Feb 6, 2020

when is allowed inside type Foo = object but not inside type Foo = enum; this proposal is to allow:

type Foo = enum
  foo1
  when bar:
    foo2
  else:
    foo3
  foo4
type
  NimNodeKind* = enum
    ...
    when defined(nimHasCustomDefSection):
      nnkCustomDefSection,
    ...
  • there are obviously other use cases, eg:
type Foo = enum
  kBaz
  when defined windows:
    kFoo
  kBar
@timotheecour timotheecour changed the title allow when in enum types allow when in enum types Feb 6, 2020
@Varriount
Copy link

I like this, the only possible issue is that this can affect the ordinal value of an enum

@timotheecour
Copy link
Member Author

I like this, the only possible issue is that this can affect the ordinal value of an enum

but hopefully ordinal value wouldn't be part of public interface

@Araq
Copy link
Member

Araq commented Feb 7, 2020

It's a "natural" feature, yet, I prefer to handle this via a macro. The syntactic and implementation effort would be quite severe.

@timotheecour
Copy link
Member Author

in my use case it was for NimNodeKind which can't be handled with a macro; although this is an edge case though and wouldn't justify a language feature just because of that... still not sure to do in that case...

but generally ya a macro would give maximum flexibility and no language change; feel free to close

@Araq
Copy link
Member

Araq commented Oct 28, 2020

feel free to close

Such a rare offering that I can't resist.

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

No branches or pull requests

3 participants