Skip to content

Check every declaration against what lib.ts compiles to; fix two that differed - #58

Merged
ASDAlexander77 merged 1 commit into
mainfrom
lib-declarations-check
Oct 29, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
lib-declarations-check

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Number.toString returned nothing while lib.d.ts said it returns a string, and nothing caught that until a program printing its result crashed (fixed in #56). This PR adds a check for that whole class of bug, and fixes the two declarations it found.

The check: scripts/check_declarations.ps1

A program calls a library function through its declared type, while lib.ts defines the function with its own type. The script compares the two for every function:

  1. It compiles an empty program against the declarations to MLIR. src is used as the default library through a temporary junction, so the check sees the working tree, not the last build.
  2. It compiles src/lib.ts on its own, as build_core.bat does.
  3. It compares each function's signature in the two outputs.

Some spellings describe the same signature and count as equal: int and s32, a void result and no result, and T | null versus T for a class or opaque pointer. It checks 326 functions in about a second. tests.ps1 runs it first, so a declaration that drifts from the code fails the run.

Two declarations it found

  • String.startsWith was declared with no return type, so a call had no value: const r = s.startsWith("he") left r unresolved. lib.ts returns a boolean. The new test is tests/string_object_starts_with.ts.
  • MatchResults' constructor was declared without its hasIndices parameter, so a call passed its last argument where lib.ts reads hasIndices.

Tests

DefaultLib release JIT: gc 181/181, rc and none 180 with 1 skipped, own 170 with 11 skipped. check_declarations.ps1 passes. It is Windows-only, because it uses a junction and pwsh, so tests.sh does not run it.

🤖 Generated with Claude Code

… differed

scripts\check_declarations.ps1 compiles a program against the declarations
(src as the default library) and src\lib.ts on its own, and compares each
function's signature in the two: a program calls a function by its declared
type, and lib.ts defines it with its own. Spellings of one signature (int and
s32, a void result and none, `T | null` of a pointer and T) count as the same.
tests.ps1 runs it first. Of 326 functions it found two:

- String.startsWith was declared with no result: a call had no value
  (`const r = s.startsWith("he")` left `r` unresolved), while lib.ts returns
  a boolean.
- MatchResults' constructor was declared without its `hasIndices` parameter,
  so a call passed its last argument where lib.ts reads `hasIndices`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit cb48583 into main Oct 29, 2026
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