nim-lang / RFCs

A repository for your Nim proposals.
136 stars 26 forks source link

Make "unreachable statement" error a warning #240

Closed ghost closed 4 years ago

ghost commented 4 years ago

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 commented 4 years ago

'If true: quit' is good enough

Araq commented 4 years ago

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

simonkrauter commented 4 years ago

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

juancarlospaco commented 4 years ago

when off: ?.

Clyybber commented 4 years ago

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 https://github.com/nim-lang/Nim/pull/14816) :D