Skip to content

-0 kept by unary minus and the literal -0; a getter read as a statement runs; bigint + - * with an int in 64 bits - #941

Merged
ASDAlexander77 merged 4 commits into
mainfrom
fix-negzero-getter-bigint
Nov 19, 2026
Merged

ASDAlexander77 merged 4 commits into
mainfrom
fix-negzero-getter-bigint

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Three wrong results found while adding Temporal, DataView and Float16Array to the default library (ASDAlexander77/TypeScriptCompilerDefaultLib#108, which works around all three):

  • -x of a float 0 was +0. NegativeOpValue lowered float negation to 0.0 - x; it is now arith.negf. A literal -0 folded to the integer 0; it is now the number -0. Before the fix, 1 / -v and 1 / -0 were Infinity. An int operand stays an int.
  • obj.prop; never called the getter. RemoveUnusedAccessor erased any getter whose result was unused, along with whatever the getter does (count its calls, throw). An accessor op that is an expression statement now carries __getter_statement, and the canonicalizer keeps it.
    • A field read through an interface (iface.field;) is a plain ts.Load, which calls the class's getter when the field's slot is an accessor cell. LoadOp now declares its own memory effects: a read, plus a write when the load carries __getter_statement, so dead-code removal and RemoveUnused keep that load. Every other load is unchanged.
  • bigint * 1000000000, n + 1 and 1 + n were done in 32 bits. bigint was missing from numericPromotionOrder(), so both operands were cast to the literal's si32. It is now the 64-bit rung above i64/s64, and isPromotableNumeric accepts it.

Tests

  • New: 00negative_zero.ts, 00getter_statement.ts, 00bigint_mixed_arith.ts. Each runs under gc and own, compiled and under the JIT, and under rc and none through TSLANG_CORPUS.
  • Full ctest -C Release on Windows x64: 8465/8465 passed (3 disabled).

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 commits November 19, 2026 18:37
…nt runs; bigint + - * with an int in 64 bits

- Unary minus of a float lowered to 0.0 - x, which is +0 for 0: now arith.negf. A literal -0
  folded to the integer 0: now the number -0. 1 / -v and 1 / -0 were Infinity.
- `obj.prop;` on its own: the canonicalizer erased the unused getter, and with it whatever
  the getter does. An accessor op that is an expression statement is now kept. (A field read
  through an interface whose class has a getter is a plain load, still dropped when unused.)
- bigint was not on the numeric promotion ladder, so `n * 1000000000`, `n + 1` and `1 + n`
  met at the literal's s32 and were cut to 32 bits. It is now the 64-bit rung above i64/s64.

Found while adding Temporal, DataView and Float16Array to the default library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A field of an interface may be a cell of accessors, read by a plain ts.Load that calls the
getter when it is lowered; an unused load was dead and the getter never ran. LoadOp now gives
its memory effects itself: a read, and for a load that is a statement of its own
(__getter_statement) a write as well, so it is kept. Other loads are as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cast from a signed or signless integer to bigint fell through to the
zero-extension: `const b: bigint = -5` held 4294967291. The old promotion
hid it by cutting the bigint back to 32 bits; with bigint on the ladder the
int is widened to it, so `b < 0` was false and the default library's
temporal_duration_instant and disposable_stack failed under wasm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b58d91d into main Nov 19, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-negzero-getter-bigint branch November 19, 2026 21:48
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