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

quit() fails with "unreachable statement after 'return'" #9832

Closed
smithtim opened this issue Dec 1, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@smithtim
Copy link

commented Dec 1, 2018

The following fails to compile, giving: Error: unreachable statement after 'return'

echo "hello"
quit()
echo "goodbye"

Is this expected behavior?

If so, it might be worth mentioning in the documentation that quit does not supersede the requirement that all code must be reachable. https://nim-lang.org/docs/system.html#quit%2Cint

The error message could also be improved to Error: unreachable statement after 'quit'.

@timotheecour

This comment has been minimized.

Copy link
Contributor

commented Dec 1, 2018

note: sometimes adding early return (or early quit) is useful during debugging ; one way to avoid this error is to write instead:
if true: return (probably shd work w if true: quit() too)

@GULPF

This comment has been minimized.

Copy link
Member

commented Dec 1, 2018

This is the expected behavior. This happens for all procs marked with the {.noReturn.} pragma, not only quit(). The error message could definitely be improved

@GULPF GULPF added the Error messages label Dec 1, 2018

timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 2, 2018

@timotheecour timotheecour referenced this issue Dec 2, 2018

Merged

fix #9832 #9841

@smithtim

This comment has been minimized.

Copy link
Author

commented Dec 3, 2018

I agree with @timotheecour that early return/quit can be useful in debugging. My own preference would be for reachability checking to be disabled by default. Reachability cannot be fully checked anyway, since it is an undecidable property related to the halting problem.

Is there a way to disable reachability checking? I don't see one in the compiler docs. https://nim-lang.org/docs/nimc.html

@timotheecour

This comment has been minimized.

Copy link
Contributor

commented Dec 3, 2018

maybe the error msg could mention the if true: return workaround, it's easy enough

@Araq

This comment has been minimized.

Copy link
Member

commented Dec 4, 2018

Reachability cannot be fully checked anyway, since it is an undecidable property related to the halting problem.

That's true for almost every analysis a compiler might attempt and hence an invalid argument.

@Araq Araq closed this in #9841 Dec 4, 2018

Araq added a commit that referenced this issue Dec 4, 2018

timotheecour added a commit to timotheecour/Nim that referenced this issue Dec 4, 2018

Araq added a commit that referenced this issue Dec 4, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Dec 15, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Dec 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.