Skip to content

fix: the next returned by paris should accept 2 arguments - #966

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.pairs_return
Feb 27, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.pairs_return

Conversation

@EfveZombie

Copy link
Copy Markdown

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @EfveZombie, 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 refines the type annotations for Lua's built-in pairs function within the EmmyLua code analysis resources. The update provides a more precise type signature for the iterator function returned by pairs, ensuring better static analysis and autocompletion support for Lua projects.

Highlights

  • Type Definition Correction: Corrected the EmmyLua type definition for the pairs function in global.lua to accurately reflect that the iterator function returned by pairs accepts two arguments: the table and an optional index.

🧠 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
  • crates/emmylua_code_analysis/resources/std/global.lua
    • Updated the @generic and @return type annotations for the pairs function to correctly specify the iterator's arguments and return values.
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. ↩

@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 correctly updates the LuaDoc type annotations for the pairs global function in global.lua. The previous annotation for the iterator function returned by pairs was inaccurate, indicating it accepted only one argument. The updated annotations now correctly reflect that the iterator function (typically next) accepts two arguments (the table and the current index) and introduces a generic type I for better type precision. This improves the accuracy of the type analysis for Lua's pairs function.

--- See function `next` for the caveats of modifying the table during its
--- traversal.
---@generic K, V
---@generic K, V, I

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.

medium

The introduction of the generic type parameter I in the @generic annotation for the pairs function provides a more precise type definition for the table's index. This improves the accuracy of type inference for the iterator function's index argument.

---@generic K, V, I
---@param t table<K, V> | V[] | {[K]: V}
---@return fun(tbl: any):K, V
---@return (fun(tbl: table<I, V>, index: I?):K, V), table<I, V>, I?

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.

medium

The updated @return annotation for the pairs function correctly specifies that the returned iterator function accepts two arguments: the table and an optional index. This rectifies the previous single-argument annotation, ensuring the type system accurately models Lua's next function behavior when used with pairs.

@CppCXY
CppCXY merged commit d756db8 into EmmyLuaLs:main Feb 27, 2026
22 checks passed
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