fix: resolve overload before generic constraint check#1021
Merged
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom Apr 13, 2026
Merged
fix: resolve overload before generic constraint check#1021CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
CppCXY merged 1 commit intoEmmyLuaLs:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in generic constraint checking where merged parameter types from function overloads caused false positive diagnostic errors. The implementation now resolves the specific overload matching the call arguments to ensure accurate type checking instead of using a union of all overload parameters. A regression test has been added to cover this scenario. I have no feedback to provide.
… positives from merged parameter types
084e2d5 to
0efa5d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a function has multiple
@overloadsignatures with a@generic T: tableconstraint, the generic constraint checker was producing false positivegeneric-constraint-mismatchwarnings.For example:
Root Cause
In
infer_call_doc_function(used by the generic constraint checker), when the inferred type is aSignature, it calledsignature.to_doc_func_type()which merges all overload parameter types into a union. This caused the constraint checker to seeinteger | Tas the type for the second parameter, and then incorrectly check theintegerargument against thetableconstraint ofT.Fix
When the signature has overloads, use
semantic_model.infer_call_expr_func()to resolve the matching overload first, then perform the generic constraint check on the correctly matched signature.Test
Added a regression test
test_overload_generic_constraint_merged_paramsthat reproduces the false positive scenario.