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 nimvm silently gives wrong results (implicit discard causing bugs); nimvm gives redefinition error in valid code #13450

Open
timotheecour opened this issue Feb 20, 2020 · 0 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Feb 20, 2020

when nimvm accepts invalid code (implicit discard causing bugs) or silently gives wrong results (example 2) and other errors.

Example

proc main(): int =
  when nimvm: doAssert false
  else: 123 # returns 0, implicitly discarded
  # else: result = 123 # returns 123
echo main()

Current Output

0

Expected Output

returning 123 is probably not what we want here because of the way nimvm works. However it should give error:
Error: expression '123' is of type 'int literal(123)' and has to be discarded
just like it would with if false instead of when nimvm

Example 2

when true: # D20200420T210320
  proc bar(): int =
    when nimvm: result = 2
    else: 1
  doAssert bar() == 1 # fails

Example 3

this example is a different bug, it gives: Error: redefinition of 'y'

when true: # D20200420T210337:here
  proc bar() =
    when nimvm:
      let y = 1
    else:
      let y = 2
  bar()

Additional Information

@timotheecour timotheecour changed the title when nimvm accepts invalid code (implicit discard causing bugs) when nimvm accepts invalid code (implicit discard causing bugs); nimvm gives redefinition error in valid code Apr 21, 2020
@timotheecour timotheecour changed the title when nimvm accepts invalid code (implicit discard causing bugs); nimvm gives redefinition error in valid code when nimvm silently gives wrong results (implicit discard causing bugs); nimvm gives redefinition error in valid code Nov 29, 2020
metagn added a commit to metagn/Nim that referenced this issue Oct 14, 2024
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

1 participant