Repository navigation
Overload signatures are types only; the implementation is the function - #378
Merged
Merged
Conversation
A body-less function outside an ambient context is an overload signature, but it was registered as a function. The next declaration of the same name, the implementation, then took the cached signature's parameter list, so its body indexed past the entry block's arguments: an ArrayRef assert in debug and an access violation in release, with or without a call (#343). Function overload signatures are now skipped, and so are method and constructor overload signatures in a class, which crashed the same way. Ambient declarations (`declare`, a .d.ts, imported classes, declaration-only class expressions) and abstract methods keep their meaning. Fixes #343 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.
Fixes #343. Overload signatures crashed the compiler, with or without a call:
Cause
A body-less function was registered as a function.
mlirGenFunctionSignaturePrototypelooks for an already-discovered function by its bare name. When it finds one, it reuses that function's type in place of the parameter list it has just built. So the implementationf(a, b?)took the one-parameter type of the first signature. Its entry block got one argument for two parameters, andmlirGenFunctionParamsreadarguments[1]past the end.That is why "remove either signature and it compiles" was only half true: keeping only the one-parameter signature still crashes. With the longer signature first, the result is "redefinition of symbol" instead of a crash.
Fix
mlirGen(FunctionDeclaration)now skips it. The implementation is the one function, and calls are checked against its parameter list. The overload signatures themselves are not checked against the calls.c.m(1)withm(a),m(a, b),m(a, b?) {…}).mlirGenClassMethodMemberskips them too.declare function, anything in a.d.ts(including the__declstext of-sharedmodules, which is parsed as one), imported classes, and declaration-only class expressions;abstractmethods.declare, used to be treated as an external symbol. It now fails withcan't resolve nameat the call. TypeScript rejects that code too, with TS2391 "Function implementation is missing". Nothing in this repo or in TypeScriptCompilerDefaultLib relies on it: every external declaration there usesdeclareor a.d.ts.Tests
00function_overloads.ts(compile, jit, and the rc/none corpus). It covers:abstractmethod.Not in this PR
declare functionoverloads, and a.d.tswith several signatures of one name, still report "redefinition of symbol". That is an error, not a crash. Supporting them needs real overload resolution, since each signature would be a separate external.🤖 Generated with Claude Code