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

Make "unreachable statement" error a warning #240

Closed
Yardanico opened this issue Jun 25, 2020 · 5 comments · Fixed by nim-lang/Nim#14816
Closed

Make "unreachable statement" error a warning #240

Yardanico opened this issue Jun 25, 2020 · 5 comments · Fixed by nim-lang/Nim#14816

Comments

@Yardanico
Copy link

Yardanico commented Jun 25, 2020

Currently code like

proc a() = 
  quit(0)
  echo "hi"

a()

would not compile with the error unreachable statement after 'return' statement or '{.noReturn.}' proc. I propose to make it a warning instead, which will still be quite visible to the developer but it'll allow for faster prototyping in some cases.

Please comment, I might not know some cases where this can lead to new bugs or unintended behaviour.

Also see nim-lang/Nim#14190 because it's a bit similar in a sense that this PR made it possible to have unreachable else branch in a case statement.

@timotheecour
Copy link
Member

'If true: quit' is good enough

@Araq
Copy link
Member

Araq commented Jun 25, 2020

Yeah, however, if true is an idiom that has to be learned. I'm torn.

@simonkrauter
Copy link

+1
This would make it easier and more beginner friendly, for example when inserting an early return statement for debugging purpose.

@juancarlospaco
Copy link
Contributor

when off: ?.

@Clyybber
Copy link

This:

proc a() = 
  quit(0)
  block: echo "hi"

a()

currently compiles without error, which is a bit illogical, but if we were to fix it so that it errors it would be a breaking change.
Making it a warning and fixing it would be a solution without a breaking change (I did that in nim-lang/Nim#14816) :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants