Skip to content

Conversation

xuhuanzy
Copy link
Member

No description provided.

Copy link

Summary of Changes

Hello @xuhuanzy, 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 an enhancement in the handling of generic types within the code analysis system. The primary change involves refining how rest parameters are processed when their generic type is instantiated as a tuple. Previously, the system might not have correctly expanded the elements of such a tuple into individual parameters, potentially leading to incorrect type checking. The updated logic now ensures that these tuple types are properly unfolded, allowing for accurate validation of function calls against generic definitions that utilize tuple-instantiated rest parameters.

Highlights

  • Generic Rest Parameter Expansion: Implemented logic to correctly expand tuple types when they are used to instantiate generic rest parameters in function definitions. This ensures that a generic rest parameter like ...: A where A is instantiated as [Type1, Type2] is correctly interpreted as ...: Type1, Type2.
  • New Test Case for Tuple Generics: Added test_issue_738 to validate the correct handling of generic rest parameters instantiated with tuple types, specifically checking for parameter type mismatches.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 aims to improve handling of generic variadic parameters, particularly when they resolve to a tuple type. The implementation has a critical logic flaw that can lead to parameters being dropped during type instantiation, which I've provided a fix for. Additionally, the new test case has an inverted assertion that would cause it to fail on correct code. I've included a suggestion to correct the test's logic.

Expand tuple types when encountering rest parameters (`...`) during generic instantiation

close EmmyLuaLs#738
@xuhuanzy xuhuanzy linked an issue Oct 1, 2025 that may be closed by this pull request
@xuhuanzy xuhuanzy linked an issue Oct 5, 2025 that may be closed by this pull request
@Aetherall
Copy link

Hi @xuhuanzy, sorry to bother, I wondered if this PR was allowing to infer the content of generic types captured in parameter ?

Something along the lines of

---@generic T
---@param future Future<T> 
---@return T
---@async
function await(future)
  return future:wait()
end

--- somewhere in uv coroutine context
local result = await fetchUser() --- Future<User>
---    ^ User

Anyway I am so gratetful to start a lua project in this times where this project make it really close to type systems I am used to working with ! Really a great future for embedded scripting <3

@xuhuanzy
Copy link
Member Author

xuhuanzy commented Oct 5, 2025

@Aetherall This PR is not needed. It already supported capturing generic parameters before this PR. This PR provides advanced usage, such as conditional types, mapped types, etc.

image

@xuhuanzy
Copy link
Member Author

xuhuanzy commented Oct 5, 2025

Awesome ! Won't this alias definition be simplified by the checker though ? will it work with

---@alias Future<T> { wait: fun () -> T }
image

@Aetherall
Copy link

I must be using incorrect version or settings, thanks for the confirmation ! Mapped types will allow me to remove a really big chunk of annotations in my project ahah many thanks for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants