Repository navigation
bigint: literals are bigint, 64-bit /, % and shifts, wrapper calls convert - #727
Merged
Merged
Conversation
…nvert - A bigint literal is typed `bigint` (it was a plain i64). `x ?? 7n` of an optional bigint failed in LLVM (`bigint | i64`, and an i64 compared with a null pointer), and `5n` given for `bigint | string` was an invalid cast. `??` also takes a bigint for a value that is never null. - A literal that does not fit 64 bits is an error: 12345678901234567890n printed -6101065172474983726. - `/`, `%`, shifts and bitwise operators of bigints stay 64-bit integers: `10n / 3n` was 3.33333 through a number, and `1n << 40n` was 256, shifted by 40 mod 32 through an i32. - `Number(x)`, `BigInt(x)`, `String(x)` and `Boolean(x)` called without `new` convert to the primitive, as in JavaScript: they made the class's object, so `BigInt(42) + 1n` and `Number(x) + 0.5` were invalid casts. Tests: 00bigint_ops (gc, rc, none), diagnostic-location/bigint_literal_out_of_range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Makes
bigintusable: three compile failures, two silently wrong results, and the standard conversion calls.Literals are
bigint. A bigint literal was typed as a plaini64, so:x ?? 7non an optional bigint merged intobigint | i64and failed in LLVM (an i64 compared with a null pointer);5ngiven for abigint | stringparameter was an invalid cast.The literal is now a
bigint.??also treats a bigint as never null, as it does anumber.Out-of-range literals are an error. A bigint is a 64-bit signed integer here, and
12345678901234567890nsilently printed-6101065172474983726. It's now a compile error./,%, shifts and bitwise operators stay 64-bit integers. Previously:10n / 3nwas3.33333, computed through anumber;1n << 40nwas256, shifted by 40 mod 32 through an i32.Both now give the bigint results (
3n,1099511627776n). This includes the compound forms (/=,<<=).Number(x),BigInt(x),String(x)andBoolean(x)withoutnewconvert to the primitive, as in JavaScript. They used to make the wrapper object, soBigInt(42) + 1nandNumber(x) + 0.5failed as invalid casts.new Number(x)still makes the object.Tests:
00bigint_opsruns under gc, rc and none;diagnostic-location/bigint_literal_out_of_rangechecks the error;tests/bigint_conversions.ts, linked PR). It passes under gc, rc, none and own.Validated on Windows: ctest 6213/6213; DefaultLib release passes under gc (175), rc and none (174 + 1 gc-only skip), own (164 + 11 not-own skips).
Not changed:
10n / 0nis still a hardware divide fault rather than JavaScript'sRangeError;**on bigints still goes throughnumber.Found, not fixed: under rc, none and own,
assert(new Number(5).toString() == "5", ...)crashes at run time. It's unrelated to this change.🤖 Generated with Claude Code