Skip to content

fix(flow): separate dynamic loop divergence from infinite loops - #1039

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/missing-return-dynamic-loops
Apr 20, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:fix/missing-return-dynamic-loops

Conversation

@lewis6991

Copy link
Copy Markdown
Collaborator

Summary

  • split runtime-dependent loop divergence from proven infinite loops in return-flow analysis
  • keep MissingReturn fallthrough-friendly for dynamic while and repeat loops when a later return is still reachable
  • rename the helper to does_func_body_satisfy_missing_return so the API matches the softer diagnostic contract

Testing

  • cargo test -p emmylua_code_analysis check_return_count_test -- --nocapture
  • cargo test -p emmylua_code_analysis

@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 return flow analysis for Lua functions by introducing a more granular distinction between proven infinite loops (is_infinite) and runtime-dependent divergence (may_diverge). It renames several fields and functions to better reflect their purpose in the diagnostic pipeline, specifically for the MissingReturn check. The review feedback highlights that loops with constant conditions (e.g., while true) should not be marked as strictly infinite if they contain a break statement, as this could lead to false positives in reachability analysis.

@lewis6991
lewis6991 force-pushed the fix/missing-return-dynamic-loops branch from bcc92ca to b889c09 Compare April 17, 2026 12:58
Track runtime-dependent loop divergence separately from proven infinite
loop bodies in return-flow analysis.

Keep MissingReturn fallthrough-friendly when a later explicit return is
still reachable, including constant-condition loops whose bodies can
break at runtime. Preserve the stronger infinite-loop signal for loops
that truly cannot exit, and rename the helper used by the diagnostic to
reflect that narrower contract.
@lewis6991
lewis6991 force-pushed the fix/missing-return-dynamic-loops branch from b889c09 to fef8322 Compare April 17, 2026 14:30
@lewis6991

Copy link
Copy Markdown
Collaborator Author

/gemini review

@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 return flow analysis in the Lua code analyzer to better distinguish between code that falls through, proven infinite loops, and runtime-dependent divergence. Key changes include renaming can_continue to can_fall_through and can_stall to is_infinite, as well as introducing a may_diverge flag. The MissingReturn diagnostic was updated to utilize these more granular flags, allowing for more accurate detection of missing return statements in functions containing loops. Additionally, several unit tests were added to verify the improved analysis logic. I have no feedback to provide as there were no review comments to evaluate.

@CppCXY
CppCXY merged commit 530a951 into EmmyLuaLs:main Apr 20, 2026
16 checks passed
@lewis6991
lewis6991 deleted the fix/missing-return-dynamic-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.

2 participants