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

runtime use of compileTime proc should error immediately, not at codegen #10535

Open
timotheecour opened this issue Feb 2, 2019 · 1 comment
Labels
VM see also `const` label

Comments

@timotheecour
Copy link
Member

timotheecour commented Feb 2, 2019

proc fun(){.compileTime.} =
  echo "step2"

static: echo "step1"

fun() # user error: should've been: `static: fun()`

static: echo "step3 (with side effects) that expects step2 to run before"

nim c main.nim prints:

step1
step3 (with side effects) that expects step2 to run before
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0176.nim(8, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0176.nim(10, 1) Error: request to generate code for .compileTime proc: fun
  fun() # user error: should've been: `static: fun()`
  ^

expected output:

step1
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0176.nim(8, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/tests/nim/all/t0176.nim(10, 1) Error: compileTime proc: fun used in a run time context # <= msg can be something like this ****
  fun() # user error: should've been: `static: fun()`
  ^

ie, compilation should stop earlier and not keep going past the point where fun() is used in a non CT context

other confusing example

I faced a situation (nimterop/nimterop#102 (comment)) where the error Error: request to generate code for .compileTime proc: fun was never printed because "step 3" errored as a result of "step 2" not being run at CT; in more complex cases than above simplified example this is hard to diagnose.

@liquidev
Copy link
Contributor

liquidev commented Apr 3, 2021

I agree that the error message should be changed, it was quite confusing when I stumbled onto it the first time. Perhaps attempt to use compileTime proc 'fun' at runtime would be a bit more clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

No branches or pull requests

2 participants