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

when false doesn't work inside a generic #8924

Open
timotheecour opened this issue Sep 9, 2018 · 2 comments
Open

when false doesn't work inside a generic #8924

timotheecour opened this issue Sep 9, 2018 · 2 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Sep 9, 2018

bugs:

  • when false doesn't work as I'd expect in case6 (also, it's inconsistent with case1)
  • case7 also could be a bug
import std/macros

when defined(case1):
  # works: nothing printed
  proc test1()=
    when false:
      dumpTree:
        discard 1+1

when defined(case2):
  # works: nothing printed
  when false:
    proc test1()=
      dumpTree:
        discard 1+1

when defined(case3):
  # works: nothing printed
  proc test1()=
    when false:
      static: echo "foo"

when defined(case4):
  # works: nothing printed because template not instantiated
  proc test1[]()=
    static: echo "foo"

when defined(case5):
  # works: prints `foo` because not a template
  proc test1()=
    static: echo "foo"

when defined(case6):
  # BUG: prints StmtList(etc) despite `when false`
  proc test1[]()= # likewise with `s/[]/[T]`
    when false:
      dumpTree:
        discard 1+1

when defined(case7):
  # BUG: prints StmtList etc despite generic not instantiated
  proc test1[]()=
    dumpTree:
      discard 1+1
@timotheecour timotheecour changed the title when false ignored by dumpTree when false ignored by dumpTree when inside a generic Sep 9, 2018
@timotheecour timotheecour changed the title when false ignored by dumpTree when inside a generic when false doesn't work inside a generic Sep 9, 2018
@LemonBoy
Copy link
Contributor

Nah, what happens here is that semGenericStmt expands the dumpTree macros since it has to look at the instantiated AST, the when block is correctly evaluated at the instantiation site.
If you swap the dumpTree: ... block with a static one you'll see that when false works just fine.

@timotheecour
Copy link
Member Author

timotheecour commented Sep 10, 2018

sorry I fail to see the logic. Why shouldn't when false: foo just disable foo? Anything else seems buggy. Especially case1 vs case6 is inconsistent.
As it stands, when false (or when defined(posix) when we are on windows etc) is not a reliable way to disable a piece of code.

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