Add simple check for functions containing both return; and return <obj> (DO NOT MERGE) #1541
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.
This is a rebased and tweaked version of PR #466. The main changes compared to that are:
TryNextMethod()
, which internally is coded asreturn TRY_NEXT_METHOD
, and does not treat it as the function returning an object; this fixes a false positive in theViewObj
method inlib/teaching.g
(and probably elsewhere).CodeReturnVoidWhichIsNotProfiled
(which did not exist when (WIP) Add a simple check against functions containing both return; and return <obj>; #466 was created)I found this useful, as it flagged several places in GAP and packages where I genuinely think it was a bug that a function sometimes returns a value and sometimes nothing.
However, even with all the work combined, one false (?) positive remains:
ErrorInner
inlib/error.g
is meant to sometimes return something or not, intentionally. However, I am not sure anything ever uses its return value? There are a fewreturn Error(...)
in the GAP library (most of them in the meataxe code), but I think most could and should be replaced by a call toErrorNoReturn
. Similarly for packages.And lots of packages produce warnings. And the code is still not doing an actual code flow analysis; so in order to avoid tons of spurious complaints about functions caused by the implicit
return;
we add to the end of function that don't end in areturn
statement, we ignore those implicit returns. This ensures we don't get a warning about this function:But on the other hand, it also means we don't get a warning about this function, even though we'd like to:
Anyway, ultimately, we should not add this directly, but only enable it when requested -- see issue #1191.