Closed metagn closed 3 weeks ago
Superb work.
Thanks for your hard work on this PR! The lines below are statistics of the Nim compiler built from 42e8472ca6eab740c0879428bd119ec94e70fe74
Hint: mm: orc; opt: speed; options: -d:release 178683 lines; 8.401s; 753.098MiB peakmem
fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677
The false positive in #23677 was caused by behavior in
implicitlyDiscardable
where only the last node ofif
/case
/try
etc expressions were considered, as in the final node of the final branch (in this caseelse
). To fix this we use the same iteration inimplicitlyDiscardable
that we use inendsInNoReturn
, with the difference that for anif
/case
/try
statement to be implicitly discardable, all of its branches must be implicitly discardable.noreturn
calls are also considered implicitly discardable for this reason, otherwise stuff likeif true: discardableCall() else: error()
doesn't compile.However
endsInNoReturn
also had bugs, one wherefinally
was considered in noreturn checking when it shouldn't, another where onlynkIfStmt
was checked and notnkIfExpr
, and the node given for the error message was bad. SoendsInNoReturn
now skips overskipForDiscardable
which no longer containsnkIfStmt
/nkCaseStmt
/nkTryStmt
, stores the first encountered returning node in a var parameter for the error message, and handlesfinally
andnkIfExpr
.Fixing #23677 already broke a line in
syncio
so some package code might be affected.