Repository navigation
TSLANG_ISSUES 5: @cpp C++ overloads under one name, picked by the arguments - #576
Merged
Merged
Conversation
A @cpp class can declare a C++ overload set under the C++ name, each method with its own @slot (or @Linkname for a non-virtual one). Before, a second declaration of a name was "redefinition of symbol", and tsbindgen wrote `scale_2`, `scale_3`, which quietly changed meaning when a header added an overload above them. - mlirGenClassCppOverloadNames renames an overload after the first to `name#N` (`#` is in no identifier), once the base classes are known: a method in the slot of a base class's overload takes that overload's name, which is how it overrides it. - resolveCppOverload: at the call, after the arguments are generated, the overload the arguments fit best is picked from the class and its bases, as C++ does: the argument's own type, then an integer for an integer or a float for a float (`number` is f64), then any other conversion. No fit, or two equal fits, is an error listing them. - An override of an overloaded base method without @slot is an error, and so is a @slot overload with the parameters of a base method in another slot (that method, overridden in the wrong slot). - DeclarationPrinter prints the declared name; the importer renames again. Diagnostics print the declared name too. - tsbindgen keeps the C++ name for overloads (a field of the name still gives `_2`). Tested against real C++ (cppvtable/abi_host.cpp): virtual overloads in MSVC's reversed order, non-virtual ones by symbol, and C++ calling overloads implemented in tslang. TSLANG_ISSUES.md 5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 13, 2026
Merged
ASDAlexander77
added a commit
that referenced
this pull request
Oct 17, 2026
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.
TSLANG_ISSUES.md 5: C++ overloads in
@cppclasses.A
@cppclass can now declare a C++ overload set under its C++ name. Each method has its own@slot(or@linknamefor a non-virtual one), and a call picks the overload from its arguments at compile time, as C++ does:Before, a second declaration of a name was a
redefinition of symbolerror. tsbindgen wrotescale_2,scale_3, so a binding regenerated after the header gained an overload silently called a different method.How:
mlirGenClassCppOverloadNamesrenames each overload after the first toname#Nin the AST, so every name derived from it stays consistent;#can't appear in a TypeScript identifier. It runs once the base classes are known. A method in the slot of a base class's overload takes that overload's name, which is how it overrides it. It is idempotent across discovery and import passes.resolveCppOverloadruns inmlirGenCallExpressiononce the arguments exist. It collects the overloads from the object's class and its bases, deduplicating overrides by name and slot. It scores each argument: 3 for its own type (number≡f64), 2 for integer→integer or float→float, 1 for any other conversion. It rebuilds the callee withClassMethodAccess. No fit, or two equal best fits, is an error that lists the overloads.@slot;@slotoverload with the same parameters as a base method in another slot. That keeps the existingslot_overrideerror: it is the same method overridden in the wrong slot.DeclarationPrinterprints the declared name, and the importer renames again.@cppdiagnostics print declared names._2. Docs updated: README,docs/cpp-classes.md,TSLANG_ISSUES.mditem 5.Tests:
cppvtable/abi_host.cpp(real C++, built by the host compiler) gains:over(int),over(double),over(int, int);scaled(double);Callback::pick(int)/pick(double)implemented in tslang and called from C++.test-jit-cppvtable-abipasses with MSVC locally. The Itanium slots (7/8/9, 5/6) and_ZN7Methods6scaledEdfollow declaration order and the mangling rules, and Linux CI runs them. The Itanium compile tests checkCounter's vtable, includingpickandpick#1.00cpp_overloads.ts: hand-made vtable, base and derived overloads, an override by slot, integer/float/u8/number/string arguments.Error tests:
overload_no_match,overload_ambiguous,overload_override.export/import_cppvtable_class: overloads cross__decls, and the exporting module picks the same overload.TsClangImporterTestsand the bindgen C++ test now use one name.Full Release suite: all passed, after updating the two tests that expected the old behavior (
TsClangImporterTests, and the ownership verifier, which now skips00cpp_overloads.tslike the other@cpptests).🤖 Generated with Claude Code