Skip to content

An optional union with no value is false in a condition (path.ts on wasm) - #815

Merged
ASDAlexander77 merged 1 commit into
mainfrom
wasm-path-maybe
Nov 11, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
wasm-path-maybe

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Fixes path.ts hanging on wasm. The bug isn't wasm-specific: it shows whenever the program is compiled with the default library, natively too.

What went wrong

  • With the default library, Readonly<Path> expands to an object type, so Maybe<Readonly<Path>> is optional<null | {key, prev, typename}>.
  • while (curr) casts that to boolean. The cast took the optional's default when it has no value: a zeroed union whose type is "undefined". It then tested that against null, which it isn't, so the result was true.
  • When curr.prev was undefined the loop kept going, pushing garbage, until memory ran out (wasm64) or a read went out of bounds (wasm32).
  • ctest compiles path.ts without the default library, where the parameter stays an interface, so it never saw this.

The fix (MLIRGenCast.cpp)

  • An optional union cast to boolean now tests HasValue first; with no value it is false.

Tests

  • New 00optional_union_truthiness reproduces it without the default library (while, if, !, ?: over null | undefined | {...}). The old compiler hangs on it.
  • path.ts is taken off wasm_skips.txt.
  • Native ctest: 6976/6976.
  • wasm suites, release, 0 failures (debug: path.ts and the new test pass):
Suite none / rc own
tester, wasm32 and wasm64 577 pass (was 575) 421 pass
defaultlib 181 pass 180 pass

Under own, both tests are refused natively too (addPath returns a borrowed field), so the runner counts them as NATIVE.

🤖 Generated with Claude Code

…)` over `null | undefined | {...}` ends

A cast of an optional union to boolean took the optional's default, a zeroed union whose type is
"undefined", and tested it against null: not null, so true. With the default library, path.ts's
Readonly<Path> is such a tuple and its loop never ended (natively too; ctest runs it without the
default library). A boolean target now tests HasValue first.

path.ts is taken off the wasm skips; 00optional_union_truthiness reproduces it without the library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 9ae70e4 into main Nov 11, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the wasm-path-maybe branch November 11, 2026 23:33
ASDAlexander77 added a commit that referenced this pull request Nov 12, 2026
…'s tests

PR #829's run booted the emulator and passed everything but two tester
tests, 00class_override_arity and 00optional_union_truthiness, under every
model: both came after v0.0-pre-alpha124 with the compiler fixes they check
(#811, #815). When the job takes a published release's package, it now takes
that release's tslang/test/tester/tests and CMakeLists.txt too; the runner
and its skips stay the commit's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77 added a commit that referenced this pull request Nov 12, 2026
…829)

* Android emulator tests: make the AVD where the emulator looks for it

Release run 43251862764's emulator exited at once: "Unknown AVD name
[tslang_api29_x86_64] ... no file tslang_api29_x86_64.ini in
$HOME/.android/avd". The runner's avdmanager had made it elsewhere. The run
job sets ANDROID_USER_HOME and ANDROID_AVD_HOME for both, and the install
step checks that `emulator -list-avds` names the AVD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Android emulator tests: a published package runs with its own release's tests

PR #829's run booted the emulator and passed everything but two tester
tests, 00class_override_arity and 00optional_union_truthiness, under every
model: both came after v0.0-pre-alpha124 with the compiler fixes they check
(#811, #815). When the job takes a published release's package, it now takes
that release's tslang/test/tester/tests and CMakeLists.txt too; the runner
and its skips stay the commit's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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