Repository navigation
Report a call with too few arguments (TS2554) instead of padding it with undef - #341
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ith undef
A missing argument is now padded only for a parameter that may be omitted
(!ts.optional - optional and default-valued parameters -, !ts.undefined,
!ts.void) or the rest parameter. Any other missing parameter is reported as
"Expected N arguments, but got M." ("N-M" with omittable trailing
parameters, "at least N" with a rest parameter). The counts are what the
user wrote: mlirGenCallFunction passes how many operands it inserted in
front (the `this` of a bound function - method, constructor, closure
capture - or of an extension function).
A conditional call (`f?.(...)`) swallowed the failure of the inner call and
left an empty branch, which for a void callee dropped the call silently; it
now fails.
The two suite tests that relied on the padding now pass the arguments.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…nsertion guard - positive.ts: reword the undefined-parameter comment; tsc does not omit `b: undefined` (TS2554), only `void`, which tslang cannot even write as a parameter type. - CMakeLists.txt: add FAIL_REGULAR_EXPRESSION to the call-arity negative tests so a crash after the expected message no longer passes silently. - MLIRGenAccessCall.cpp: guard the optional-call (f?.(...)) insertion point so EXIT_IF_FAILED's early return can't leave the builder stuck inside the IfOp's then-block. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 22, 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.
Summary
A call that passes fewer arguments than the callee requires is now a compile error, as in TypeScript (TS2554). Until now tslang padded the missing arguments with
undefand compiled on.That is not theoretical. It hid a real bug in the default library:
RegExp.replaceAllcalled the nativeregexp_replacewith 3 of its 4 arguments. At x64 the missing argument happened to still be in a register, so it worked; at i686 it was an uninitialised stack slot, and the program crashed. The plan is indocs/superpowers/plans/2026-09-23-call-arity-check.md.The check
mlirGenPrepareCallOperandsis the one place missing arguments were padded. Before padding, it now reports:Expected 2 arguments, but got 1.Expected 2-3 arguments, but got 1.when trailing parameters may be omittedExpected at least 1 arguments, but got 0.for varargs (TypeScript's own grammar)A parameter may be omitted when its type is
optional(bothb?: Tand a default-valuedb = 5),undefinedorvoid. Everything else is an error.The numbers count what the user wrote. The compiler inserts operands of its own (
this, a bound method's receiver, a closure's captures), andmlirGenCallFunction— the only caller — now passes that count explicitly rather than having it guessed from operand types.f?.(...)no longer swallows the failure. With a void callee the call was silently dropped; otherwise the module failed verification with no message about arguments.Class expressions no longer run the constructor
let X = class { constructor(a: number, b: number) {...} }evaluated to a constructed instance, which meant the constructor ran at the class definition with no arguments for its parameters.00interface_newprinted an extraCall ctor : 0, 0. A class expression's value only has to carry the class, so it is now allocated with its vtable and no constructor call. Interface casts still work, because the value is a real object.Tests
new S()against a two-parameter constructor, andgen<string[]>(). Both now pass their arguments.Not in this PR
this:parameter now gets a false error with a wrong count (m(this: O, a: number, b: number)calledo.m(1, 2)reportsExpected 3 arguments, but got 2.), for class, interface and object-literal methods. The cause is older than this PR: such signatures carry the receiver twice, so these calls previously miscompiled in silence, putting the first argument into thethisslot and leaving the last parameterundef. There is no live use of that shape in this repo or the default library (the only one is commented out in00lambdas.ts), and extension and namespace functions usingthis:— every real use, including the default library's ~150 — count correctly. Worth its own issue.function f(a: number): number; function f(a: number, b: number): number; function f(a: number, b?: number) {...}). This predates the change: a debug build asserts inArrayRef. Also worth its own issue.Test plan
ctest -j 16 -C Release: 2786/2786. That's 2771 plus 6 registrations for the class-expression test and 9 arity tests.TSLANG_LIB_PATHin the environment.it.next(), generic classes, methods and default parameters, inheritance with explicit and implicitsuper(), interface and bound methods, object-literal methods, and default-library calls that rely on default parameters (toFixed(),padEnd(5),split(),join(),sort()). All compile.🤖 Generated with Claude Code