Skip to content

A declared function redeclared: one declaration, or a clear error - #386

Merged
ASDAlexander77 merged 1 commit into
mainfrom
declared-function-overload-error
Sep 28, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
declared-function-overload-error

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Declaring a function a second time failed with an error from the verifier, whether or not the signature was the same:

declare function abs(x: i32): i32;
declare function abs(x: i32, y: i32): i32;   // error: redefinition of symbol named 'abs'

This is the last item from the #231 review, and it follows the decision to report a clear error rather than support overloads. A declared function binds one external symbol, and a C function has one signature. Picking a signature per call would call one C function with several ABIs.

Change

  • A different signature now reports:
    error: 'abs' is declared again with another signature: a declared function is one external symbol,
           so it can't have overloads. Declare it once, with optional or union parameters, or give each
           signature a name of its own and bind them with @linkname
    
  • The same declaration again, such as one C function declared in two .d.ts files, is left to the first one instead of failing.

mlirGen(FunctionDeclaration) records, for each declared function's full name, the declaration it came from and the module it was generated into. The record is per module because:

  • the discovery module is thrown away;
  • a -shared library's __decls text is parsed again for the next pass, so the same declaration arrives as a new AST node.

A first version keyed only by name made the real pass skip those as repeats, which broke 83 -shared tests before it was pushed.

Declarations in different namespaces have different full names and are not compared.

Tests

  • New test-compile-declare-overloads-error expects the new message and fails on redefinition of symbol, a stack dump or an assert.
  • New 00declare_function_twice.ts (compile and jit): the same declaration twice, called.
  • Full release suite: 2990/2990 passed.
  • TypeScriptCompilerDefaultLib tests, release jit and compile: 156/156 each. lib.d.ts is full of declares.

🤖 Generated with Claude Code

@ASDAlexander77
ASDAlexander77 merged commit de015d4 into main Sep 28, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the declared-function-overload-error branch September 28, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant