Skip to content

fix(flow): reuse ordered return analysis for loop exits - #1037

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/ordered-return-analysis-loops
Apr 17, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/ordered-return-analysis-loops

Conversation

@lewis6991

Copy link
Copy Markdown
Collaborator

Replace the old missing-return special cases with the same ordered block
walker used for inferred returns. This avoids false MissingReturn
diagnostics for functions that return from truthy while/repeat loops,
keeps break and repeat-until flow consistent across inference and
diagnostics, and adds regressions for closure returns, diagnostics, and
module exports.

@lewis6991
lewis6991 force-pushed the fix/ordered-return-analysis-loops branch from 513f888 to 056ec9d Compare April 16, 2026 13:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the function body return analysis by introducing a FuncBodyFlow struct to track control flow states such as continuation, exit, and divergence. This enhancement allows for more accurate return type inference and diagnostic checks, particularly for loops with truthy conditions (e.g., while true). The check_return_count diagnostic was simplified to leverage this new flow analysis. A logic error was identified in the repeat_flow implementation regarding how infinite loops affect the ability of a function to continue past the loop structure.

@lewis6991
lewis6991 force-pushed the fix/ordered-return-analysis-loops branch 3 times, most recently from 65dc617 to 6619bc3 Compare April 16, 2026 16:37
Use the same ordered block walker for inferred returns, MissingReturn,
and module return selection so loops, breaks, and stalling paths follow
the same control-flow rules.

Keep `pred()`-style call conditions dynamic instead of pruning branches
from their inferred return type, and add Lua block regressions for
closure returns, module exports, and MissingReturn.
@lewis6991
lewis6991 force-pushed the fix/ordered-return-analysis-loops branch from 6619bc3 to 66f9ec1 Compare April 17, 2026 09:56
@CppCXY
CppCXY merged commit 3530d81 into EmmyLuaLs:main Apr 17, 2026
16 checks passed
@clason

clason commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

regression in nvim-treesitter's indent.lua: spurious

Annotations specify that a return value is required here.

at line 344.

@lewis6991

Copy link
Copy Markdown
Collaborator Author

#1039

@lewis6991
lewis6991 deleted the fix/ordered-return-analysis-loops branch May 1, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants