nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
238 stars 64 forks source link

Make 'Unreachable statement' a warning #2838

Open privat opened 2 months ago

privat commented 2 months ago

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.

github-actions[bot] commented 2 months ago

Test Results

    67 files     338 suites   16m 46s :stopwatch: 14 184 tests 13 643 :white_check_mark: 541 :zzz: 0 :x: 14 810 runs  14 222 :white_check_mark: 588 :zzz: 0 :x:

Results for commit 43e78843.