Repository navigation
fix: select(n, func()) correctly narrows type when func returns multiple values - #962
Conversation
…ple values When a multi-return function call was the sole variadic argument to select(), the T... template was binding T to the whole Variadic(Multi(...)) wrapper instead of expanding it. This caused instantiate_variadic_type to produce a doubly-nested Variadic(Base(Variadic(Multi(...)))) which bypassed the index-slicing logic in instantiate_select_call, returning the wrong type. Fix: in variadic_tpl_pattern_match, when the single argument is itself a Variadic(Multi([T1, T2, ...])), expand it via insert_multi_types so the template receives all return values rather than the Variadic wrapper. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Summary of ChangesHello @nickvonkaenel, 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 addresses a critical type inference bug within the 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a type narrowing issue with select(n, func()) when func returns multiple values. The added test case is well-crafted and specifically targets the fixed scenario. The implementation changes in variadic_tpl_pattern_match are logical and correctly handle the unpacking of variadic arguments. Overall, this is a solid fix. I have one minor suggestion to improve code consistency.
…mod.rs Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
please fix the check |
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Should be fixed now |
Summary
select(2, func())wherefunc()returns(integer, string)was resolving tointeger|stringinstead ofstringvariadic_tpl_pattern_matchbound the templateTto the entireVariadic(Multi([integer, string]))wrapper rather than expanding itinstantiate_variadic_typeto produce a doubly-nestedVariadic(Base(Variadic(Multi(...)))), which bypassed the index-slicing logic ininstantiate_select_callFix
In
variadic_tpl_pattern_match(tpl_pattern/mod.rs), when matching aTplRefvariadic template against a single argument that is itself aVariadic, expand it instead of storing it as-is:Variadic(Multi([T1, T2, ...]))→insert_multi_types([T1, T2, ...])soT...instantiates toVariadic(Multi([T1, T2, ...]))Variadic(Base(T))→insert_multi_base(T)preserving unbounded variadic semanticsTest plan
select(n, multi_ret())wheremulti_ret()returns(integer, string), asserting result isstringtest_select_typecases still pass (variadic..., literal args,select('#', ...))🤖 Generated with Claude Code