Repository navigation
Report a missing return statement in a closure or function - #7738
Merged
Merged
Conversation
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
✅ Deploy Preview for nextflow-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
jorgee
approved these changes
Oct 2, 2026
jorgee
left a comment
Contributor
There was a problem hiding this comment.
Looks fine to me. I ran an agent to look for false positives in common patterns (>> publish closures, process and workflow bodies, each/subscribe, if / else if / else chains, try/catch and throw), and it found none.
One corner case, non-blocking: an empty body reports the error without a source position.
channel.of(1).map { x -> }
def f(x: Integer) -> String { }Error main.nf:-1:-1: Missing return statement
The top-level addReturnsIfNeeded(node, node) uses the empty block as its own fallback, and an empty block has no position. Passing the function or closure node as the fallback would fix it. It's a rare case, so up to you whether to fix it here or wait until someone reports it.
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Close #7737
The type checker turns the trailing statement of each code path into an implicit return, but never checked that every path actually yields a value. So this passed, and the closure emits
nullwhenever the condition is false:Now, when a function or closure must return a value, every code path must end with an explicit
returnor a trailing expression statement (or athrow). Otherwise it reportsMissing return statementon the statement where the path ends. That covers:ifwith noelse, or an empty branch (reported on theif)def y = 'a'ory = 'a', which were previously treated as implicit returnstry/catchwhere thetryblock or acatchblock doesn't return. Before, a trailingtry/catchwas never checked at allThe check only applies when a value is required: a non-void declared return type, an unresolved generic such as the
Rinmap, or adeffunction where some path returns a value. Void functions and closures are unaffected.Because predicate closures must return a value (#7714), a
filterclosure that only returns inside anifis also reported, even though the fall-throughnullwould be treated asfalse.