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

No short-circuit evaluation in static context (ex. when) #14631

Closed
dawkot opened this issue Jun 10, 2020 · 2 comments
Closed

No short-circuit evaluation in static context (ex. when) #14631

dawkot opened this issue Jun 10, 2020 · 2 comments
Labels
VM see also `const` label

Comments

@dawkot
Copy link

dawkot commented Jun 10, 2020

Because compiles((let _ = (echo "")) is false, compiler probably shouldn't try to compile (echo "") is int.

Example

template foo(x) =
  when compiles((let _ = x)) and x is int:
    discard

foo:
  echo ""

Current Output

Error: expression 'echo [""]' has no type (or is ambiguous)

Additional Information

Nim 1.2.0 and current devel 6aa971d

@timotheecour
Copy link
Member

see #13541 + whole discussion around it

@timotheecour timotheecour added the VM see also `const` label label Jun 10, 2020
@jibal
Copy link

jibal commented Jul 4, 2020

It doesn't and shouldn't work that way. compiles((let _ = x)) and x is int is an expression and must be well formed.
Use when (when compiles((let _ = x)): x is int else: false):

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

3 participants