Repository navigation
A @cpp method called through ?. picks among its overloads - #602
Merged
Merged
Conversation
`obj?.mix(1, 2, 3)` called the first overload, `mix(a, b)`, with three arguments: the member access is made in a conditional of its own, and the call saw only the value of its optional result, so resolveCppOverload could not tell which method it was, and the call was not a C++ call (ts.cpp_call). The method is now accessed again from the object the callee is bound to, inside the call's own region. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
obj?.mix(1, 2, 3)on a@cppclass withmix(a, b)andmix(a, b, c)called the first overload,mix(a, b), and passed it three arguments. There was no diagnostic. Direct calls (obj.mix(1, 2, 3)) were already correct.With
?., the member access is built in onets.Ifand the call in a later one. The call only sawts.Valueof the optional result, soresolveCppOverloadcouldn't tell which method it was. The call also lostts.cpp_call.Fix
cppMethodAccessAgain(MLIRGenAccessCall.cpp): when the optional callee comes from a@cppmethod access, the method is accessed again inside the call's region, fromts.GetThisof the bound function. The object's own class is used, so a derived class's overloads count. After that the normal path runs: overload resolution,ts.cpp_call.Tests
00cpp_overloads.ts: a newMixerclass whose overloads differ only in arity (2 vs 3 params), called directly and through?.. It also covers?.on a derived class (override, own overload, base overload) and?.on null.Not in this PR
ts.CallIndirecthas no too-many-args check (new C().m(1, 2, 3)on a 2-param method compiles). That is why this miscompile was silent. It is being handled separately.🤖 Generated with Claude Code