Skip to content

fix(diagnostic): handle constrained generic function calls in call-non-callable#970

Merged
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
lewis6991:fix/callgeneric
Mar 2, 2026
Merged

fix(diagnostic): handle constrained generic function calls in call-non-callable#970
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
lewis6991:fix/callgeneric

Conversation

@lewis6991
Copy link
Collaborator

call/non-callable analysis treated template refs as definitively
non-callable and did not consistently use template constraints during
callability checks.

Fixes:

  • infer_call_expr_func now handles TplRef/ConstTplRef/StrTplRef by
    resolving through get_tpl_ref_extend_type before call inference.
  • added a recursion guard when the resolved constraint type is
    unchanged.
  • call_non_callable checker now evaluates template refs via their
    constraints in has_non_callable_member.
  • union non-callable collection now reuses has_non_callable_member for
    consistent filtering.

…n-callable

call/non-callable analysis treated template refs as definitively
non-callable and did not consistently use template constraints during
callability checks.

Fixes:
- infer_call_expr_func now handles TplRef/ConstTplRef/StrTplRef by
  resolving through get_tpl_ref_extend_type before call inference.
- added a recursion guard when the resolved constraint type is
  unchanged.
- call_non_callable checker now evaluates template refs via their
  constraints in has_non_callable_member.
- union non-callable collection now reuses has_non_callable_member for
  consistent filtering.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lewis6991, 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 issue where the call-non-callable diagnostic incorrectly flagged generic function calls involving template references. The changes enhance the type inference system to properly resolve and evaluate template constraints, ensuring that the diagnostic accurately identifies callable types and avoids false positives for valid generic function usages.

Highlights

  • Template Reference Handling: The infer_call_expr_func now correctly processes TplRef, ConstTplRef, and StrTplRef types by resolving their extended types before performing call inference.
  • Recursion Guard: A recursion guard has been implemented in the template reference resolution logic to prevent infinite loops when the resolved constraint type remains unchanged.
  • Improved Callability Checks: The call_non_callable checker now accurately evaluates template references by considering their constraints within the has_non_callable_member function.
  • Consistent Union Type Filtering: The union non-callable collection mechanism now reuses has_non_callable_member for more consistent and accurate filtering of callable types.

🧠 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/src/diagnostic/checker/call_non_callable.rs
    • Modified has_non_callable_member to include logic for TplRef, ConstTplRef, and StrTplRef by checking their constraints.
    • Updated collect_non_callable_union_types to use !has_non_callable_member for filtering, ensuring consistent callability checks.
  • crates/emmylua_code_analysis/src/diagnostic/test/call_non_callable_test.rs
    • Added a new test case test_no_call_non_callable_for_generic_function_param_in_a_lua to validate the fix for generic function parameters.
  • crates/emmylua_code_analysis/src/semantic/infer/infer_call/mod.rs
    • Imported get_tpl_ref_extend_type for template reference resolution.
    • Extended infer_call_expr_func to handle TplRef, ConstTplRef, and StrTplRef by delegating to a new infer_tpl_ref_call function.
    • Introduced infer_tpl_ref_call function to resolve template references and prevent recursion if the type remains unchanged.
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
Contributor

@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 effectively addresses an issue with call analysis on constrained generic functions. The changes in infer_call_expr_func to resolve template references and the corresponding updates in has_non_callable_member are well-implemented and correctly handle template constraints. The addition of a new test case is also a great inclusion. I have one suggestion to improve maintainability by reducing code duplication.

@CppCXY CppCXY merged commit ac67817 into EmmyLuaLs:main Mar 2, 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