From af5241f94e343a7a67b6f522d65164d16e843e28 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Thu, 19 Nov 2026 18:37:32 +0000 Subject: [PATCH 1/3] -0 kept by unary minus and the literal -0; a getter read as a statement 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 --- tslang/include/TypeScript/Defines.h | 3 ++ tslang/lib/TypeScript/LowerToLLVM.cpp | 4 +- tslang/lib/TypeScript/MLIRGenImpl.h | 20 ++++++++- tslang/lib/TypeScript/MLIRGenStatements.cpp | 16 +++++++ tslang/lib/TypeScript/TypeScriptOps.cpp | 5 ++- tslang/test/tester/CMakeLists.txt | 18 ++++++++ .../test/tester/tests/00bigint_mixed_arith.ts | 18 ++++++++ .../test/tester/tests/00getter_statement.ts | 43 +++++++++++++++++++ tslang/test/tester/tests/00negative_zero.ts | 19 ++++++++ 9 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 tslang/test/tester/tests/00bigint_mixed_arith.ts create mode 100644 tslang/test/tester/tests/00getter_statement.ts create mode 100644 tslang/test/tester/tests/00negative_zero.ts diff --git a/tslang/include/TypeScript/Defines.h b/tslang/include/TypeScript/Defines.h index 38b01782d..91314ab09 100644 --- a/tslang/include/TypeScript/Defines.h +++ b/tslang/include/TypeScript/Defines.h @@ -300,6 +300,9 @@ // the field's function as a hybrid): the address of the class field a tagged slot's cell names, or // null where the slot can't be written (a method's cell, or an object literal's field) #define INTERFACE_FUNCTION_FIELD_WRITE_ATTR "__function_field_write" +// on an accessor op whose getter is read as a statement of its own (`obj.prop;`): the canonicalizer keeps +// it though nothing uses its result, as the call is the point +#define GETTER_STATEMENT_ATTR "__getter_statement" #define INSTANCEOF_NONE_NAME ".instanceOf.none" #define MAIN_ENTRY_NAME "main" #define TS_NEST_ATTRIBUTE "ts.nest" diff --git a/tslang/lib/TypeScript/LowerToLLVM.cpp b/tslang/lib/TypeScript/LowerToLLVM.cpp index 83c93a9b5..8c2baed57 100644 --- a/tslang/lib/TypeScript/LowerToLLVM.cpp +++ b/tslang/lib/TypeScript/LowerToLLVM.cpp @@ -5196,8 +5196,8 @@ LogicalResult NegativeOpValue(mlir_ts::ArithmeticUnaryOp &unaryOp, mlir::Value o } else if (!type.isIntOrIndex() && type.isIntOrIndexOrFloat()) { - builder.replaceOpWithNewOp(unaryOp, type, clh.createFConstantOf(type.getIntOrFloatBitWidth(), 0.0), - oper); + // negf, not 0.0 - x: that is +0 for x = 0, where -x is -0 (1 / -x was Infinity) + builder.replaceOpWithNewOp(unaryOp, type, oper); return mlir::success(); } else diff --git a/tslang/lib/TypeScript/MLIRGenImpl.h b/tslang/lib/TypeScript/MLIRGenImpl.h index de64501e2..c99c92a58 100644 --- a/tslang/lib/TypeScript/MLIRGenImpl.h +++ b/tslang/lib/TypeScript/MLIRGenImpl.h @@ -6536,6 +6536,20 @@ class MLIRGenImpl auto intType = mlir::cast(intAttr.getType()); auto constType = constantOp.getType(); auto valAttr = intAttr; + // `-0` is the number -0, as in JavaScript: as an integer it was 0, and + // 1 / -0 was Infinity + if (intAttr.getValue().isZero() && isa(constType)) + { +#ifdef NUMBER_F64 + auto floatType = mlir::Float64Type::get(builder.getContext()); +#else + auto floatType = mlir::Float32Type::get(builder.getContext()); +#endif + auto negZero = builder.getFloatAttr(floatType, APFloat::getZero(floatType.getFloatSemantics(), true)); + return (mlir::Value) builder.create( + location, mlir_ts::LiteralType::get(negZero, getNumberType()), negZero); + } + if (intType.isSignless()) { intType = builder.getIntegerType(intType.getWidth(), true); @@ -9238,7 +9252,9 @@ class MLIRGenImpl // sits at this rung because that is where it promotes, not because it is 64 bits wide. // An unsigned type follows the signed and signless ones of its width. Missing from the // ladder, `u64 * 2` found only the literal's s32 and multiplied in 32 bits. - getNumberType(), builder.getF64Type(), builder.getI64Type(), SInt(64), UInt(64), builder.getIndexType(), + // A bigint is a 64-bit integer, and the rung above the others of its width: missing from the + // ladder, `n * 1000000000` found only the literal's s32 and multiplied in 32 bits. + getNumberType(), builder.getF64Type(), getBigIntType(), builder.getI64Type(), SInt(64), UInt(64), builder.getIndexType(), builder.getF32Type(), SInt(32), builder.getI32Type(), UInt(32), builder.getF16Type(), SInt(16), builder.getI16Type(), UInt(16), SInt(8), builder.getI8Type(), UInt(8) @@ -9257,7 +9273,7 @@ class MLIRGenImpl return false; } - return isa(type) || type.isIntOrIndexOrFloat(); + return isa(type) || type.isIntOrIndexOrFloat(); } bool syncTypes(mlir::Location location, mlir::Type type, mlir::Value &leftExpressionValue, mlir::Value &rightExpressionValue, const GenContext &genContext) diff --git a/tslang/lib/TypeScript/MLIRGenStatements.cpp b/tslang/lib/TypeScript/MLIRGenStatements.cpp index 132878f5f..ee252032c 100644 --- a/tslang/lib/TypeScript/MLIRGenStatements.cpp +++ b/tslang/lib/TypeScript/MLIRGenStatements.cpp @@ -734,6 +734,22 @@ namespace mlirgen } EXIT_IF_FAILED(result) + + // `obj.prop;` calls the getter, as in JavaScript, though nothing uses what it gives: the + // canonicalizer erased an unused getter, and with it whatever the getter does + if (result.value) + { + if (auto *defOp = result.value.getDefiningOp()) + { + if (mlir::isa(defOp)) + { + defOp->setAttr(GETTER_STATEMENT_ATTR, builder.getUnitAttr()); + } + } + } + return mlir::success(); } diff --git a/tslang/lib/TypeScript/TypeScriptOps.cpp b/tslang/lib/TypeScript/TypeScriptOps.cpp index bd2ac79cb..ec80d45e8 100644 --- a/tslang/lib/TypeScript/TypeScriptOps.cpp +++ b/tslang/lib/TypeScript/TypeScriptOps.cpp @@ -376,8 +376,9 @@ template struct RemoveUnusedAccessor : public OpRewritePattern LogicalResult matchAndRewrite(T op, PatternRewriter &rewriter) const override { - // a setter call has side effects; otherwise erase only an unused getter - if (op.getSetValue() || !op.getValue().use_empty()) + // a setter call has side effects; otherwise erase only an unused getter, and not one that is a + // statement of its own (`obj.prop;`), whose call is the point + if (op.getSetValue() || !op.getValue().use_empty() || op->hasAttr(GETTER_STATEMENT_ATTR)) { return failure(); } diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index f1d2f6f11..b8deb212e 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -2662,6 +2662,9 @@ tslang_add_test(NAME test-jit-none-strings COMMAND test-runner -jit -mm=none "${ # every single-file test the default model runs, in either tier set(TSLANG_CORPUS + 00negative_zero.ts + 00getter_statement.ts + 00bigint_mixed_arith.ts 00private_name_in.ts 00type_literal_accessors.ts 00array_conversions.ts @@ -5489,6 +5492,21 @@ tslang_add_test(NAME test-compile-own-00-in-union-of-classes COMMAND test-runner tslang_add_test(NAME test-jit-00-in-union-of-classes COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00in_union_of_classes.ts") tslang_add_test(NAME test-jit-own-00-in-union-of-classes COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00in_union_of_classes.ts") +# -0 kept by unary minus and the literal -0; a getter read as a statement runs; a bigint with a number literal or an +# int is done in 64 bits. rc and none run them from TSLANG_CORPUS. +tslang_add_test(NAME test-compile-00-negative-zero COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00negative_zero.ts") +tslang_add_test(NAME test-compile-own-00-negative-zero COMMAND test-runner -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00negative_zero.ts") +tslang_add_test(NAME test-jit-00-negative-zero COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00negative_zero.ts") +tslang_add_test(NAME test-jit-own-00-negative-zero COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00negative_zero.ts") +tslang_add_test(NAME test-compile-00-getter-statement COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00getter_statement.ts") +tslang_add_test(NAME test-compile-own-00-getter-statement COMMAND test-runner -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00getter_statement.ts") +tslang_add_test(NAME test-jit-00-getter-statement COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00getter_statement.ts") +tslang_add_test(NAME test-jit-own-00-getter-statement COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00getter_statement.ts") +tslang_add_test(NAME test-compile-00-bigint-mixed-arith COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00bigint_mixed_arith.ts") +tslang_add_test(NAME test-compile-own-00-bigint-mixed-arith COMMAND test-runner -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00bigint_mixed_arith.ts") +tslang_add_test(NAME test-jit-00-bigint-mixed-arith COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00bigint_mixed_arith.ts") +tslang_add_test(NAME test-jit-own-00-bigint-mixed-arith COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00bigint_mixed_arith.ts") + # Shared (spec 23): counted handles. These are not in the own_test list, whose # test-own-no-counting check forbids __tslang_inc_ref: a handle is counted under own by design. # own_shared_user_named: a program's own class named Shared wins over the built-in (spec 23.1). diff --git a/tslang/test/tester/tests/00bigint_mixed_arith.ts b/tslang/test/tester/tests/00bigint_mixed_arith.ts new file mode 100644 index 000000000..b2c7da8f8 --- /dev/null +++ b/tslang/test/tester/tests/00bigint_mixed_arith.ts @@ -0,0 +1,18 @@ +// +, - and * of a bigint and a number literal or an int are done in 64 bits: bigint was not on the +// promotion ladder, so the operands met at the literal's s32 and the product was cut to 32 bits +const K = 1000000000; + +function main() { + const s: bigint = 1710505800; + assert(s * 1000000000 == 1710505800000000000, "bigint * literal"); + assert(1000000000 * s == 1710505800000000000, "literal * bigint"); + assert(s * K == 1710505800000000000, "bigint * const"); + const k: int = 1000000000; + assert(s * k == 1710505800000000000, "bigint * int"); + const big: bigint = 9000000000000000000; + assert(big + 1 == 9000000000000000001, "bigint + literal"); + assert(1 + big == 9000000000000000001, "literal + bigint"); + assert(big - 1 == 8999999999999999999, "bigint - literal"); + assert(big > 1, "a comparison keeps the bigint"); + print("done."); +} diff --git a/tslang/test/tester/tests/00getter_statement.ts b/tslang/test/tester/tests/00getter_statement.ts new file mode 100644 index 000000000..b42743d7e --- /dev/null +++ b/tslang/test/tester/tests/00getter_statement.ts @@ -0,0 +1,43 @@ +// obj.prop; on its own calls the getter, as in JavaScript: the getter was erased as unused, and with it +// what it does (here, count its calls or throw) +class Counter { + public reads = 0; + + get value(): int { + this.reads++; + return 7; + } + + get failing(): int { + throw "read"; + } + + static count = 0; + + static get next(): int { + Counter.count++; + return Counter.count; + } +} + +function main() { + const c = new Counter(); + c.value; + c.value; + assert(c.reads == 2, "a getter read as a statement runs"); + (c.value); + assert(c.reads == 3, "in parentheses too"); + + Counter.next; + assert(Counter.count == 1, "a static getter"); + + let threw = false; + try { + c.failing; + } catch (e) { + threw = true; + } + + assert(threw, "a getter that throws, throws"); + print("done."); +} diff --git a/tslang/test/tester/tests/00negative_zero.ts b/tslang/test/tester/tests/00negative_zero.ts new file mode 100644 index 000000000..94152ecf2 --- /dev/null +++ b/tslang/test/tester/tests/00negative_zero.ts @@ -0,0 +1,19 @@ +// -x of a float 0 is -0, as in JavaScript, and so is the literal -0: the negation was 0.0 - x, which is +// +0 for 0, and -0 was the integer 0, so 1 / -0 and 1 / -v were Infinity +function negate(v: number): number { + return -v; +} + +function main() { + assert(1 / negate(0) == -Infinity, "-v of 0 is -0"); + assert(1 / negate(-0) == Infinity, "-v of -0 is 0"); + assert(negate(1.5) == -1.5, "-v of 1.5"); + assert(1 / -0 == -Infinity, "the literal -0"); + const z = -0; + assert(1 / z == -Infinity, "a constant of -0"); + const f: f32 = 0; + assert(1 / -f == -Infinity, "an f32"); + let i: int = 0; + assert(-i == 0, "an int stays an int"); + print("done."); +} From bc86cbd1ac7b6a9e90fda708ec2982a2a114b00c Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Thu, 19 Nov 2026 18:59:32 +0000 Subject: [PATCH 2/3] iface.field; on its own calls the getter too 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 --- tslang/include/TypeScript/Defines.h | 5 +-- tslang/include/TypeScript/TypeScriptOps.td | 7 ++-- tslang/lib/TypeScript/MLIRGenStatements.cpp | 10 ++++++ tslang/lib/TypeScript/TypeScriptOps.cpp | 18 +++++++++-- .../test/tester/tests/00getter_statement.ts | 32 +++++++++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/tslang/include/TypeScript/Defines.h b/tslang/include/TypeScript/Defines.h index 91314ab09..df3efec66 100644 --- a/tslang/include/TypeScript/Defines.h +++ b/tslang/include/TypeScript/Defines.h @@ -300,8 +300,9 @@ // the field's function as a hybrid): the address of the class field a tagged slot's cell names, or // null where the slot can't be written (a method's cell, or an object literal's field) #define INTERFACE_FUNCTION_FIELD_WRITE_ATTR "__function_field_write" -// on an accessor op whose getter is read as a statement of its own (`obj.prop;`): the canonicalizer keeps -// it though nothing uses its result, as the call is the point +// on an accessor op whose getter is read as a statement of its own (`obj.prop;`), or a load of an +// interface's field read so (`iface.field;`, which may call a getter): kept though nothing uses its result, +// as the call is the point #define GETTER_STATEMENT_ATTR "__getter_statement" #define INSTANCEOF_NONE_NAME ".instanceOf.none" #define MAIN_ENTRY_NAME "main" diff --git a/tslang/include/TypeScript/TypeScriptOps.td b/tslang/include/TypeScript/TypeScriptOps.td index f4281ba54..39050301d 100644 --- a/tslang/include/TypeScript/TypeScriptOps.td +++ b/tslang/include/TypeScript/TypeScriptOps.td @@ -1449,13 +1449,14 @@ def TypeScript_SwapOp : TypeScript_Op<"Swap", [AllTypesMatch<["first", "second"] ); } -def TypeScript_LoadOp : TypeScript_Op<"Load", []> { +def TypeScript_LoadOp : TypeScript_Op<"Load", [DeclareOpInterfaceMethods]> { let summary = "loads the value from the reference type"; let description = [{ - The `load` operation loads the value from the reference value. + The `load` operation loads the value from the reference value. It reads the reference; one that is + a statement of its own (`iface.field;`, marked __getter_statement) may call a getter and is kept. }]; - let arguments = (ins Arg:$reference); + let arguments = (ins TypeScript_RefOrBoundRefOrValueRef:$reference); let results = (outs AnyType:$result); diff --git a/tslang/lib/TypeScript/MLIRGenStatements.cpp b/tslang/lib/TypeScript/MLIRGenStatements.cpp index ee252032c..73622653f 100644 --- a/tslang/lib/TypeScript/MLIRGenStatements.cpp +++ b/tslang/lib/TypeScript/MLIRGenStatements.cpp @@ -747,6 +747,16 @@ namespace mlirgen { defOp->setAttr(GETTER_STATEMENT_ATTR, builder.getUnitAttr()); } + + // an interface's field, which the class may give by a getter: read through a cell of + // accessors when the load is lowered + if (auto loadOp = mlir::dyn_cast(defOp)) + { + if (loadOp.getReference().getDefiningOp()) + { + loadOp->setAttr(GETTER_STATEMENT_ATTR, builder.getUnitAttr()); + } + } } } diff --git a/tslang/lib/TypeScript/TypeScriptOps.cpp b/tslang/lib/TypeScript/TypeScriptOps.cpp index ec80d45e8..8b5ba24f2 100644 --- a/tslang/lib/TypeScript/TypeScriptOps.cpp +++ b/tslang/lib/TypeScript/TypeScriptOps.cpp @@ -320,8 +320,9 @@ template struct RemoveUnused : public OpRewritePattern LogicalResult matchAndRewrite(T op, PatternRewriter &rewriter) const override { - // report failure when nothing was erased: the greedy driver re-scans after every success - if (!op->getResult(0).use_empty()) + // report failure when nothing was erased: the greedy driver re-scans after every success. A read + // that is a statement of its own may call a getter (an interface's field): kept + if (!op->getResult(0).use_empty() || op->hasAttr(GETTER_STATEMENT_ATTR)) { return failure(); } @@ -520,6 +521,19 @@ void mlir_ts::LoadOp::getCanonicalizationPatterns(RewritePatternSet &results, ML results.insert>(context); } +// A load reads its reference. A field of an interface may be a cell of accessors, and then the load calls +// the getter: one that is a statement of its own (`iface.field;`, __getter_statement) says it writes as +// well, or a load nothing uses was dead and the getter never ran. +void mlir_ts::LoadOp::getEffects(SmallVectorImpl> &effects) +{ + effects.emplace_back(MemoryEffects::Read::get(), &getOperation()->getOpOperand(0), 0, false, + SideEffects::DefaultResource::get()); + if (getOperation()->hasAttr(GETTER_STATEMENT_ATTR)) + { + effects.emplace_back(MemoryEffects::Write::get(), SideEffects::DefaultResource::get()); + } +} + //===----------------------------------------------------------------------===// // ValueOp //===----------------------------------------------------------------------===// diff --git a/tslang/test/tester/tests/00getter_statement.ts b/tslang/test/tester/tests/00getter_statement.ts index b42743d7e..62babcd55 100644 --- a/tslang/test/tester/tests/00getter_statement.ts +++ b/tslang/test/tester/tests/00getter_statement.ts @@ -1,5 +1,17 @@ // obj.prop; on its own calls the getter, as in JavaScript: the getter was erased as unused, and with it // what it does (here, count its calls or throw) +interface HasValue { + value: int; +} + +interface HasFailing { + failing: int; +} + +class Plain { + value = 3; +} + class Counter { public reads = 0; @@ -31,6 +43,11 @@ function main() { Counter.next; assert(Counter.count == 1, "a static getter"); + // an interface's field, which the class gives by a getter + const h: HasValue = c; + h.value; + assert(c.reads == 4, "through an interface"); + let threw = false; try { c.failing; @@ -39,5 +56,20 @@ function main() { } assert(threw, "a getter that throws, throws"); + + let threwThroughInterface = false; + const f: HasFailing = c; + try { + f.failing; + } catch (e) { + threwThroughInterface = true; + } + + assert(threwThroughInterface, "through an interface, in a try"); + + // a plain field read so is only a read + const p: HasValue = new Plain(); + p.value; + assert(p.value == 3, "a field"); print("done."); } From 4e65869bdcf95560d32209b4020a3d54b617106e Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Thu, 19 Nov 2026 21:13:22 +0000 Subject: [PATCH 3/3] An int becomes a bigint sign-extended 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 --- tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h | 4 +++- tslang/test/tester/tests/00bigint_mixed_arith.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h b/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h index 87f58dd96..45485b69a 100644 --- a/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h +++ b/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h @@ -266,9 +266,11 @@ class CastLogicHelper // a wider integer keeps the value: a signed or sign-neutral (iN) one sign-extends, only an unsigned one // zero-extends (castLLVMTypesLogic, which sees signless LLVM types only). `let c: i64 = -7` held // 4294967289, `let n = s.length; n = -1` held 4294967295, and `i16` -300 compared as 65236. + // A bigint is a signed i64 too: `const b: bigint = -5` held 4294967291, so `b < 0` was false. if (auto inIntType = dyn_cast(inType)) { - if (!inIntType.isUnsigned() && inIntType.getWidth() > 1 && (isa(resType) || resType.isIndex()) + if (!inIntType.isUnsigned() && inIntType.getWidth() > 1 + && (isa(resType) || resType.isIndex() || isa(resType)) && resLLVMType.getIntOrFloatBitWidth() > inLLVMType.getIntOrFloatBitWidth()) { return rewriter.create(loc, resLLVMType, in); diff --git a/tslang/test/tester/tests/00bigint_mixed_arith.ts b/tslang/test/tester/tests/00bigint_mixed_arith.ts index b2c7da8f8..9d2dbddab 100644 --- a/tslang/test/tester/tests/00bigint_mixed_arith.ts +++ b/tslang/test/tester/tests/00bigint_mixed_arith.ts @@ -14,5 +14,14 @@ function main() { assert(1 + big == 9000000000000000001, "literal + bigint"); assert(big - 1 == 8999999999999999999, "bigint - literal"); assert(big > 1, "a comparison keeps the bigint"); + + // an int becomes a bigint sign-extended: zero-extended, -1000000 was 4293967296 + const neg: bigint = -1000000; + assert(neg < 0, "a negative bigint is below 0"); + assert(neg * 2 == -2000000, "a negative bigint * literal"); + const m: int = -5; + const fromInt: bigint = m; + assert(fromInt == -5 && fromInt < 0, "a negative int as a bigint"); + assert(s * -1 == -1710505800, "bigint * a negative literal"); print("done."); }