feat(code-analysis): support @return_overload flow narrowing#974
feat(code-analysis): support @return_overload flow narrowing#974lewis6991 wants to merge 1 commit intoEmmyLuaLs:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the type inference system by introducing support for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
c6cde6a to
b5acb01
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive support for @return_overload tags, enabling advanced flow narrowing for correlated multi-return values in condition flow. The changes span across parsing, AST representation, semantic analysis, and type inference, including updates to the standard library definitions and semantic token highlighting. The implementation correctly handles generic type instantiation and variadic returns within overload rows, and includes robust test cases for various narrowing scenarios, including re-assignment and swapped equality operands. Overall, this is a well-implemented and significant feature enhancement.
| if overload_types.is_empty() { | ||
| return Some(()); | ||
| } |
There was a problem hiding this comment.
The analyze_return_overload function currently returns Some(()) if overload_types is empty. While this prevents errors, an empty @return_overload tag might indicate an incomplete or incorrect annotation by the user. Consider adding a diagnostic report in this case to provide clearer feedback to the developer using the tag.
|
@CppCXY what do you think about this? Admittedly I got AI to implement all of this, but I guided it best I could and reviewed all the changes. I'm not sure how good the overall strategy is here, but it seems to align with how other stuff is analysed. There's some slight code duplication with literal comparison narrowing, but that can be improved later. |
|
How do return overloads match with generics, and what would |
8faae77 to
f3e4466
Compare
|
Good catch, It didn't handle it well, though either did I ended up running a "review, fix, minimize" loop in codex which ended up finding lots of edge cases to fix. This has made this PR much bigger, but ~40% is tests. On local ok, status, payload = pcall(pcall, produce)
-- ok - boolean
-- status - boolean|string
-- payload - R1|stringThis PR (with and without local ok, status, payload = pcall(pcall, produce)
-- ok - true|false
-- status - string|true|false
-- payload - string|integer |
f3e4466 to
851cc8f
Compare
Add `---@return_overload` support end-to-end and use it to narrow correlated multi-return values in condition flow. - Parse/AST: - add `return_overload` token/syntax kinds - parse `---@return_overload <type>(, <type>)*` - add doc AST node and lexer/tag wiring - Analyzer/index: - handle `LuaDocTag::ReturnOverload` - store overload rows on `LuaSignature` - compute return type from overload rows (slot-wise union, variadic-aware) - Flow infra: - track `decl -> (call_expr, return_index)` mappings in binder/flow tree - clear stale mappings on reassignment - Narrowing: - add overload condition model (truthy/falsy/eq/neq) - narrow target vars using discriminant vars from the same call - support swapped equality operand order in binary condition flow - Stdlib/semantic tokens: - annotate `pcall` with `@return_overload` rows - highlight `TkTagReturnOverload` as a doc tag
851cc8f to
520475a
Compare
Add
---@return_overloadsupport end-to-end and use it to narrow correlatedmulti-return values in condition flow.
return_overloadtoken/syntax kinds---@return_overload <type>(, <type>)*LuaDocTag::ReturnOverloadLuaSignaturedecl -> (call_expr, return_index)mappings in binder/flow treepcallwith@return_overloadrowsTkTagReturnOverloadas a doc tag