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

generics execute compile time code in wrong order #11947

Open
timotheecour opened this issue Aug 14, 2019 · 2 comments
Open

generics execute compile time code in wrong order #11947

timotheecour opened this issue Aug 14, 2019 · 2 comments
Labels
Documentation Content Related to documentation content (not generation).

Comments

@timotheecour
Copy link
Member

timotheecour commented Aug 14, 2019

The generic prepass order seems buggy, resulting in incomprehensible semantics (eg #8924), see also below.

that means if you add a static: doAssert false or when false: seemsDisabledButIsNot the results are not what you'd expect and differ from what would happen inside a non-generic proc.

Example2

  import std/macros

  macro mfun7*(a: untyped): untyped =
    echo "ok7"
  macro mfun8*(a: static int): untyped =
    echo "ok8"

  template mfun5() =
    static: echo "ok5"
  template mfun2() =
    static: echo "ok2"
  template mfun4() =
    echo "ok4"

  proc fun[T]() = # no bug if non-generic
    static:
      echo "ok3"
      mfun4()
      static:
        echo "ok1"
      mfun2()
    mfun5()
    static: echo "ok6"
    mfun7(1)
    mfun8(1)

  fun[int]()

Current Output

mfun7 (with no static param) is evaluated too early

ok7
ok1
ok2
ok3
ok4
ok5
ok6
ok8

Expected Output

same as for when fun is not generic:

ok1
ok2
ok3
ok4
ok5
ok6
ok7
ok8

Additional Information

@timotheecour timotheecour changed the title generic prepass executes code in wrong order, and gives FieldError generics execute static code in wrong order, and gives FieldError Aug 14, 2019
@timotheecour timotheecour changed the title generics execute static code in wrong order, and gives FieldError generics execute compile time code in wrong order, and gives FieldError Aug 14, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Aug 14, 2019
@timotheecour
Copy link
Member Author

timotheecour commented Aug 14, 2019

see #11950 which fixes 1st part
the fact the 1st part exists only for generics is because a different code path is being used for generics vs regular procs for calling macros. The 2nd part is still there.

@timotheecour timotheecour changed the title generics execute compile time code in wrong order, and gives FieldError generics cannot call macros (gives FieldError) and execute compile time code in wrong order Aug 14, 2019
Araq pushed a commit that referenced this issue Aug 15, 2019
@timotheecour timotheecour changed the title generics cannot call macros (gives FieldError) and execute compile time code in wrong order generics execute compile time code in wrong order Aug 15, 2019
@Araq
Copy link
Member

Araq commented Aug 16, 2019

The "different code path" is a feature and this is your basic mistake:

Expected Output
same as for when fun is not generic

It's simply not like that in Nim with its semi-checked generics.

@Araq Araq added the Documentation Content Related to documentation content (not generation). label Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation).
Projects
None yet
Development

No branches or pull requests

2 participants