feat(code-analysis): support @return_overload flow narrowing#974
feat(code-analysis): support @return_overload flow narrowing#974lewis6991 wants to merge 8 commits 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.
crates/emmylua_code_analysis/src/compilation/analyzer/doc/type_ref_tags.rs
Outdated
Show resolved
Hide resolved
|
@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 |
851cc8f to
520475a
Compare
|
You might consider using conditional generics to handle this instead of introducing new syntax. |
I think we should stick to simple rules. The current complex generics are immature and need another round of refactoring and rethinking. We can adopt |
|
After analysis, for conditional generics to work as intended, built-in generics would have to be introduced. In that case, there’s essentially no fundamental difference from |
d38a552 to
fc64b9d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
All approaches based on |
057d366 to
28e0c10
Compare
28e0c10 to
062e069
Compare
062e069 to
0f238cb
Compare
This PR adds correlated
---@return_overloadrows for multi-return APIs.Today, plain
---@returndocs flatten each return slot independently, which loses the relationship between valueslike
okandresult.---@return_overloadlets each annotation row describe one possible return tuple, so theanalyzer can preserve that correlation through inference and control-flow narrowing.
What Changed
---@return_overload.mixed RHS calls, and branch joins.
Coverage Added