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

BUG: case inconsistently accepts set of argument #8537

Closed
timotheecour opened this issue Aug 5, 2018 · 2 comments
Closed

BUG: case inconsistently accepts set of argument #8537

timotheecour opened this issue Aug 5, 2018 · 2 comments

Comments

@timotheecour
Copy link
Member

BUG: the 1st of {nnkIdent, nnkSym}: is allowed
the 2nd one of {nnkEmpty, nnkLiterals}: is not allowed, giving compile error

seems like the 1st one should also give compiler error?
either way, it's inconsistent

import macros

proc replaceNodes(ast: NimNode): NimNode =
  proc inspect(node: NimNode): NimNode =
    case node.kind:
    of {nnkIdent, nnkSym}: #this set one is allowed, seems like a BUG
    # of nnkIdent, nnkSym:
      return ident($node)
    of {nnkEmpty, nnkLiterals}: # this one is not allowed, giving Error: type mismatch: got <set[NimNodeKind]> but expected 'NimNodeKind = enum'
    # of nnkEmpty, nnkLiterals: # this would work
      return ident($node)
    else:
      var rTree = node.kind.newTree()
      for child in node:
        rTree.add inspect(child)
      return rTree
  result = inspect(ast)

/cc @mratsim I extracted this from your answer in #8531 (comment)

@timotheecour timotheecour changed the title BUG: case of inconsistently accepts set of argument BUG: case inconsistently accepts set of argument Aug 5, 2018
@GULPF
Copy link
Member

GULPF commented Aug 5, 2018

The use case for allowing a set is to allow the case values to be defined in a const somewhere else. The reason that {nnkEmpty, nnkLiterals} doesn't work is because nnkLiterals isn't an enum value, it's a set:

nnkLiterals* = {nnkCharLit..nnkNilLit}

@timotheecour
Copy link
Member Author

gotcha thanks! closing

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

2 participants