Make 'Unreachable statement' a warning #2838
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From a language point of view, an unreachable statement is not an error, as the code is not executed. This is bad style at best.
However, surprisingly, in Nit it was en error because adaptive typing use the flow graph to compute the static type of variables and expression. Having unreachable code make the static type of those more complex to report to the user in a stable manner.
From a software engineering point of view, having a warning let the user shortcuts method when debugging. This is anyway cleaner than using opaque predicates à la
if true then return
that do not cause a warning (maybe it should, but it is another issue).This, this PR tries to do the right thing by making unreachable statements a warning. The static type of things is however just let as is without additional type adaptation, undefined variable are also silenced.