diff --git a/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h b/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h index 500eef348..edbadd096 100644 --- a/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h +++ b/tslang/include/TypeScript/LowerToLLVM/CastLogicHelper.h @@ -110,6 +110,13 @@ class CastLogicHelper return castIntToString(in, inLLVMType.getIntOrFloatBitWidth(), inType.isSignedInteger()); } + // a bigint is a signed i64; without this case it fell through to a bare inttoptr, and + // printing one passed its value to puts as an address + if (isa(inType) && isResString) + { + return castIntToString(in, inLLVMType.getIntOrFloatBitWidth(), true); + } + if ((inLLVMType.isF16() || inLLVMType.isF32() || inLLVMType.isF64() || inLLVMType.isF128()) && isResString) { if (inLLVMType.isF16()) diff --git a/tslang/include/TypeScript/LowerToLLVM/CodeLogicHelper.h b/tslang/include/TypeScript/LowerToLLVM/CodeLogicHelper.h index b4f5f0339..3bccb0616 100644 --- a/tslang/include/TypeScript/LowerToLLVM/CodeLogicHelper.h +++ b/tslang/include/TypeScript/LowerToLLVM/CodeLogicHelper.h @@ -49,6 +49,12 @@ class CodeLogicHelper { ftype = rewriter.getF16Type(); } + else if (width == 32) + { + // not the default: with NUMBER_F64 that is f64, and an f32 compared against it (an + // f32 cast to boolean, e.g. in the ___unbox helper) is invalid IR + ftype = rewriter.getF32Type(); + } else if (width == 64) { ftype = rewriter.getF64Type(); diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h index a5820ff42..7ffa01096 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h @@ -64,6 +64,16 @@ class LLVMRTTIHelperVCLinux types.push_back({linux::I32Type::typeName}); } + void setBoolAsCatchType() + { + types.push_back({linux::BoolType::typeName}); + } + + void setI64AsCatchType() + { + types.push_back({linux::I64Type::typeName}); + } + void setStringTypeAsCatchType() { types.push_back({linux::StringType::typeName}); @@ -108,6 +118,10 @@ class LLVMRTTIHelperVCLinux { setI32AsCatchType(); } + else if (intType.getIntOrFloatBitWidth() == 64) + { + setI64AsCatchType(); + } else { LLVM_DEBUG(llvm::dbgs() << "...unsupported throw/catch integer width: " << intType << "\n";); @@ -135,6 +149,8 @@ class LLVMRTTIHelperVCLinux setF32AsCatchType(); #endif }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setI64AsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { setClassTypeAsCatchType(classType.getName().getValue()); }) .Case([&](auto anyType) { setI8PtrAsCatchType(); }) diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinuxConst.h b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinuxConst.h index 89585a7db..4b36993bb 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinuxConst.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinuxConst.h @@ -22,6 +22,12 @@ namespace I32Type constexpr const auto *typeName = "_ZTIi"; } // namespace I32Type +namespace BoolType +{ +constexpr const auto *typeName = "_ZTIb"; +} // namespace BoolType + +// also a bigint, which is an i64 namespace I64Type { constexpr const auto *typeName = "_ZTIx"; diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32.h b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32.h index ff8c2f095..e5f512565 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32.h @@ -93,6 +93,23 @@ class LLVMRTTIHelperVCWin32 throwInfoRef = I32Type::throwInfoRef; } + void setBoolAsCatchType() + { + types.push_back({BoolType::typeName, BoolType::typeInfoRef, BoolType::catchableTypeInfoRef, BoolType::catchableTypeSize}); + + catchableTypeInfoArrayRef = BoolType::catchableTypeInfoArrayRef; + throwInfoRef = BoolType::throwInfoRef; + } + + void setBigIntAsCatchType() + { + types.push_back( + {BigIntType::typeName, BigIntType::typeInfoRef, BigIntType::catchableTypeInfoRef, BigIntType::catchableTypeSize}); + + catchableTypeInfoArrayRef = BigIntType::catchableTypeInfoArrayRef; + throwInfoRef = BigIntType::throwInfoRef; + } + void setStringTypeAsCatchType() { types.push_back({StringType::typeName, StringType::typeInfoRef, StringType::catchableTypeInfoRef, pointerSize()}); @@ -162,6 +179,10 @@ class LLVMRTTIHelperVCWin32 { setI32AsCatchType(); } + else if (intType.getIntOrFloatBitWidth() == 64) + { + setBigIntAsCatchType(); + } else { LLVM_DEBUG(llvm::dbgs() << "...unsupported throw/catch integer width: " << intType << "\n";); @@ -189,6 +210,8 @@ class LLVMRTTIHelperVCWin32 setF64AsCatchType(); #endif }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setBigIntAsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { setClassTypeAsCatchType(classType.getName().getValue()); }) .Case([&](auto anyType) { setI8PtrAsCatchType(); }) diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32Const.h b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32Const.h index 04052a9b7..cc4f6e4f4 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32Const.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCWin32Const.h @@ -113,6 +113,32 @@ constexpr const auto *throwInfoRef = "_TI3H"; constexpr int catchableTypeSize = 4; } // namespace I32Type +// `bool` - a boolean is an i1, stored as a byte +namespace BoolType +{ +constexpr const auto *typeName = "._N"; +constexpr const auto *typeInfoRef = "??_R0_N@8"; +constexpr const auto *catchableTypeInfoRef = "_CT??_R0_N@81"; +constexpr const auto *catchableTypeInfoRef2 = "_CT??_R0PEAX@_N81.box"; +constexpr const auto *copyThunk2 = ".eh.copy.box._N"; +constexpr const auto *catchableTypeInfoArrayRef = "_CTA2_N.box"; +constexpr const auto *throwInfoRef = "_TI2_N.box"; +constexpr int catchableTypeSize = 1; +} // namespace BoolType + +// `__int64` - a bigint is an i64 +namespace BigIntType +{ +constexpr const auto *typeName = "._J"; +constexpr const auto *typeInfoRef = "??_R0_J@8"; +constexpr const auto *catchableTypeInfoRef = "_CT??_R0_J@88"; +constexpr const auto *catchableTypeInfoRef2 = "_CT??_R0PEAX@_J88.box"; +constexpr const auto *copyThunk2 = ".eh.copy.box._J"; +constexpr const auto *catchableTypeInfoArrayRef = "_CTA2_J.box"; +constexpr const auto *throwInfoRef = "_TI2_J.box"; +constexpr int catchableTypeSize = 8; +} // namespace BigIntType + namespace StringType { constexpr const auto *typeName = ".PEAD"; diff --git a/tslang/include/TypeScript/LowerToLLVM/UnaryBinLogicalOrHelper.h b/tslang/include/TypeScript/LowerToLLVM/UnaryBinLogicalOrHelper.h index 65ba27c8a..3400eb9ff 100644 --- a/tslang/include/TypeScript/LowerToLLVM/UnaryBinLogicalOrHelper.h +++ b/tslang/include/TypeScript/LowerToLLVM/UnaryBinLogicalOrHelper.h @@ -107,7 +107,11 @@ mlir::Value LogicOp(Operation *binOp, SyntaxKind op, mlir::Value left, mlir::Typ { return UndefTypeLogicalOp(binOp, op, builder, typeConverter, compileOptions); } - else if (leftType.isIntOrIndex() || isa(leftType) || isa(leftType)) + // a bigint is an i64; without it here a comparison of two bigints fell to the "not + // applicable" warning at the bottom and was constant false - `u == v` of equal values + // included (comparing against a literal went through the literal's own integer type) + else if (leftType.isIntOrIndex() || isa(leftType) || isa(leftType) || + isa(leftType)) { auto value = builder.create(loc, v1, left, right); return value; diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCLinux.h b/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCLinux.h index cc077a9b4..32be28ffc 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCLinux.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCLinux.h @@ -74,6 +74,11 @@ class MLIRRTTIHelperVCLinux types.push_back({linux::I32Type::typeName, TypeInfo::Value, -1}); } + void setBoolAsCatchType() + { + types.push_back({linux::BoolType::typeName, TypeInfo::Value, -1}); + } + void setI64AsCatchType() { types.push_back({linux::I64Type::typeName, TypeInfo::Value, -1}); @@ -174,6 +179,8 @@ class MLIRRTTIHelperVCLinux // compares against the int type_info - see TryOpLowering, SaveCatchVarOpLowering setI32AsCatchType(); }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setI64AsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { // we need all bases as well @@ -192,6 +199,8 @@ class MLIRRTTIHelperVCLinux // caught value throws again. setI32AsCatchType(); setF64AsCatchType(); + setBoolAsCatchType(); + setI64AsCatchType(); setStringTypeAsCatchType(); setI8PtrAsCatchType(); }) @@ -253,6 +262,8 @@ class MLIRRTTIHelperVCLinux setF32AsCatchType(); #endif }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setI64AsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { setClassTypeAsCatchType(classType.getName().getValue()); }) // An untyped `catch (e)` / `catch (e: any)` has to catch everything, and on the diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCWin32.h b/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCWin32.h index 464f2e344..b579a598a 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCWin32.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRRTTIHelperVCWin32.h @@ -134,6 +134,26 @@ class MLIRRTTIHelperVCWin32 throwInfoRef = windows::I32Type::throwInfoRef; } + void setBoolAsCatchType() + { + types.push_back({windows::BoolType::typeName, windows::BoolType::typeInfoRef, windows::BoolType::catchableTypeInfoRef, + windows::BoolType::catchableTypeSize}); + types.push_back(boxEntry(windows::BoolType::catchableTypeInfoRef2, windows::BoolType::copyThunk2)); + + catchableTypeInfoArrayRef = windows::BoolType::catchableTypeInfoArrayRef; + throwInfoRef = windows::BoolType::throwInfoRef; + } + + void setBigIntAsCatchType() + { + types.push_back({windows::BigIntType::typeName, windows::BigIntType::typeInfoRef, windows::BigIntType::catchableTypeInfoRef, + windows::BigIntType::catchableTypeSize}); + types.push_back(boxEntry(windows::BigIntType::catchableTypeInfoRef2, windows::BigIntType::copyThunk2)); + + catchableTypeInfoArrayRef = windows::BigIntType::catchableTypeInfoArrayRef; + throwInfoRef = windows::BigIntType::throwInfoRef; + } + void setStringTypeAsCatchType() { types.push_back({windows::StringType::typeName, windows::StringType::typeInfoRef, windows::StringType::catchableTypeInfoRef, @@ -231,6 +251,12 @@ class MLIRRTTIHelperVCWin32 { setI32AsCatchType(); } + else if (intType.getIntOrFloatBitWidth() == 64) + { + setBigIntAsCatchType(); + // a bigint literal is a plain i64; box it as the bigint it is + thrownType = mlir_ts::BigIntType::get(rewriter.getContext()); + } else { result = false; @@ -258,6 +284,8 @@ class MLIRRTTIHelperVCWin32 setF32AsCatchType(); #endif }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setBigIntAsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { // we need all bases as well @@ -291,6 +319,12 @@ class MLIRRTTIHelperVCWin32 { setI32AsCatchType(); } + else if (intType.getIntOrFloatBitWidth() == 64) + { + setBigIntAsCatchType(); + // a bigint literal is a plain i64; box it as the bigint it is + thrownType = mlir_ts::BigIntType::get(rewriter.getContext()); + } else { result = false; @@ -313,6 +347,8 @@ class MLIRRTTIHelperVCWin32 setF32AsCatchType(); #endif }) + .Case([&](auto boolType) { setBoolAsCatchType(); }) + .Case([&](auto bigIntType) { setBigIntAsCatchType(); }) .Case([&](auto stringType) { setStringTypeAsCatchType(); }) .Case([&](auto classType) { setClassTypeAsCatchType(classType.getName().getValue()); }) .Case([&](auto anyType) { setI8PtrAsCatchType(); }) diff --git a/tslang/include/TypeScript/MLIRLogic/TypeOfOpHelper.h b/tslang/include/TypeScript/MLIRLogic/TypeOfOpHelper.h index 05286799a..0527ac090 100644 --- a/tslang/include/TypeScript/MLIRLogic/TypeOfOpHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/TypeOfOpHelper.h @@ -125,6 +125,13 @@ class TypeOfOpHelper return "boolean"; } + // without it a bigint had no descriptor, and boxing one into an `any` handed a null + // tag to BoxOp - a silent compiler crash (and ___unbox already tests for "bigint") + if (isa(type)) + { + return "bigint"; + } + // special case if (isa(type)) { diff --git a/tslang/lib/TypeScript/LowerToLLVM.cpp b/tslang/lib/TypeScript/LowerToLLVM.cpp index 4cda19283..45cc196e0 100644 --- a/tslang/lib/TypeScript/LowerToLLVM.cpp +++ b/tslang/lib/TypeScript/LowerToLLVM.cpp @@ -229,21 +229,27 @@ class ParseIntOpLowering : public TsLlvmPattern TypeHelper th(rewriter); LLVMCodeHelper ch(op, rewriter, getTypeConverter(), tsLlvmContext->compileOptions); + // A result wider than 32 bits (a bigint is an i64) needs the `long long` functions: `atoi` + // returns an int, and `strtol` a `long`, which is also 32 bits on Windows. + auto resultType = getTypeConverter()->convertType(op.getType()); + auto wide = resultType.isIntOrFloat() && resultType.getIntOrFloatBitWidth() > 32; + auto parsedType = wide ? rewriter.getI64Type() : rewriter.getI32Type(); + // Insert the `atoi` declaration if necessary. auto i8PtrTy = th.getPtrType(); LLVM::LLVMFuncOp parseIntFuncOp; if (transformed.getBase()) { parseIntFuncOp = ch.getOrInsertFunction( - "strtol", - th.getFunctionType(rewriter.getI32Type(), {i8PtrTy, th.getPtrType(), rewriter.getI32Type()})); + wide ? "strtoll" : "strtol", + th.getFunctionType(parsedType, {i8PtrTy, th.getPtrType(), rewriter.getI32Type()})); auto nullOp = rewriter.create(op->getLoc(), th.getPtrType()); rewriter.replaceOpWithNewOp(op, parseIntFuncOp, ValueRange{transformed.getArg(), nullOp, transformed.getBase()}); } else { - parseIntFuncOp = ch.getOrInsertFunction("atoi", th.getFunctionType(rewriter.getI32Type(), {i8PtrTy})); + parseIntFuncOp = ch.getOrInsertFunction(wide ? "atoll" : "atoi", th.getFunctionType(parsedType, {i8PtrTy})); rewriter.replaceOpWithNewOp(op, parseIntFuncOp, ValueRange{transformed.getArg()}); } @@ -5109,6 +5115,8 @@ struct SaveCatchVarOpLowering : public TsLlvmPattern SmallVector> candidates{ {::typescript::linux::I32Type::typeName, mlir::IntegerType::get(ctx, 32, mlir::IntegerType::Signed)}, {::typescript::linux::F64Type::typeName, mlir_ts::NumberType::get(ctx)}, + {::typescript::linux::BoolType::typeName, mlir_ts::BooleanType::get(ctx)}, + {::typescript::linux::I64Type::typeName, mlir_ts::BigIntType::get(ctx)}, {::typescript::linux::StringType::typeName, mlir_ts::StringType::get(ctx)}, // a thrown `any` is already a box {::typescript::linux::I8PtrType::typeName, mlir_ts::AnyType::get(ctx)}}; diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index 1a33dcabd..bf5dd6d65 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -390,6 +390,7 @@ tslang_add_test(NAME test-compile-00-throw-inlined COMMAND test-runner "${PROJEC tslang_add_test(NAME test-compile-00-try-catch-sequence-and-nesting COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00try_catch_sequence_and_nesting.ts") tslang_add_test(NAME test-compile-00-throw-number-untyped-catch COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00throw_number_untyped_catch.ts") tslang_add_test(NAME test-compile-00-catch-untyped-value COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00catch_untyped_value.ts") +tslang_add_test(NAME test-compile-00-throw-bool-bigint COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00throw_bool_bigint.ts") tslang_add_test(NAME test-compile-00-using-nested-scopes COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00using_nested_scopes.ts") tslang_add_test(NAME test-compile-00-using-unwind-progress COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00using_unwind_progress.ts") tslang_add_test(NAME test-compile-00-break-continue-scope-exit COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00break_continue_scope_exit.ts") @@ -815,6 +816,7 @@ tslang_add_test(NAME test-jit-00-throw-inlined COMMAND test-runner -jit "${PROJE tslang_add_test(NAME test-jit-00-try-catch-sequence-and-nesting COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00try_catch_sequence_and_nesting.ts") tslang_add_test(NAME test-jit-00-throw-number-untyped-catch COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00throw_number_untyped_catch.ts") tslang_add_test(NAME test-jit-00-catch-untyped-value COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00catch_untyped_value.ts") +tslang_add_test(NAME test-jit-00-throw-bool-bigint COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00throw_bool_bigint.ts") tslang_add_test(NAME test-jit-00-using-nested-scopes COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00using_nested_scopes.ts") tslang_add_test(NAME test-jit-00-using-unwind-progress COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00using_unwind_progress.ts") tslang_add_test(NAME test-jit-00-break-continue-scope-exit COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00break_continue_scope_exit.ts") @@ -1705,6 +1707,7 @@ set(TSLANG_CORPUS 00switch.ts 00symbol.ts 00throw_in_catch.ts + 00throw_bool_bigint.ts 00throw_inlined.ts 00throw_number_untyped_catch.ts 00to_primitive_ops.ts diff --git a/tslang/test/tester/tests/00throw_bool_bigint.ts b/tslang/test/tester/tests/00throw_bool_bigint.ts new file mode 100644 index 000000000..32a5bc079 --- /dev/null +++ b/tslang/test/tester/tests/00throw_bool_bigint.ts @@ -0,0 +1,125 @@ +// Throwing and catching a boolean or a bigint. +// +// `throw true` and `throw 5n` were rejected at compile time ("Not supported type in throw"): the +// RTTI helpers knew no exception type for either. A boolean is thrown as a C++ `bool` (`_N` / +// `_ZTIb`) and a bigint, an i64, as an `__int64` (`_J` / `_ZTIx`), each with the same boxing entry +// the other primitives have for an untyped catch. +// +// Getting there also fixed four bigint gaps, each reachable without exceptions: +// - boxing a bigint into an `any` crashed the compiler - typeof had no name for it, so the box +// got no type tag; +// - unboxing one failed to compile - `` of an `any` holding a string parses it, and the +// parse was an `atoi` (32 bits) where an i64 was needed; +// - converting one to a string was a bare inttoptr, so `print(x)` of a bigint crashed; +// - comparing two bigint values was constant false (`u == v` with equal values included). +// And one unrelated to bigint: `` of an `any` failed to compile, because the f32 +// branch of the generated unbox compared an f32 with an f64 zero. + +function typedBool() { + let r = false; + try { + throw true; + } catch (e: boolean) { + r = e; + } + + return r; +} + +function untypedBool() { + let r = true; + try { + throw false; + } catch (e) { + r = e; + } + + return r; +} + +function boolVariable() { + let b = 1 < 2; + let r = false; + try { + throw b; + } catch (e: boolean) { + r = e; + } + + return r; +} + +function typedBigInt() { + let r: bigint = 0n; + try { + throw 123456789012n; + } catch (e: bigint) { + r = e; + } + + return r; +} + +function untypedBigInt() { + let r: bigint = 0n; + try { + throw -5n; + } catch (e) { + r = e; + } + + return r; +} + +function mismatchPassesOn() { + let path = 0; + try { + try { + throw 7n; + } catch (e: boolean) { + path += 1; + } + } catch (e2: bigint) { + path += e2 == 7n ? 10 : 100; + } + + try { + try { + throw true; + } catch (e3: bigint) { + path += 1000; + } + } catch (e4: boolean) { + path += e4 ? 20 : 200; + } + + return path; +} + +function bigIntWithoutExceptions() { + let x: bigint = -123456789012n; + let a: any = x; + let s: string = "v=" + x; + let fromString: any = "42"; + return typeof a == "bigint" && a == x && s == "v=-123456789012" && fromString == 42n; +} + +function bigIntComparisons() { + let u: bigint = -123456789012n; + let v: bigint = -123456789012n; + let w: bigint = 7n; + return u == v && u === v && !(u != v) && u < w && w > u && u <= v && w >= u && !(w < u); +} + +function main() { + assert(typedBool(), "catch (e: boolean) catches a thrown boolean"); + assert(!untypedBool(), "an untyped catch reads a thrown boolean"); + assert(boolVariable(), "a boolean variable can be thrown"); + assert(typedBigInt() == 123456789012n, "catch (e: bigint) catches a thrown bigint"); + assert(untypedBigInt() == -5n, "an untyped catch reads a thrown bigint"); + assert(mismatchPassesOn() == 30, "boolean and bigint catches let each other's exceptions through"); + assert(bigIntWithoutExceptions(), "a bigint boxes, unboxes and converts to a string"); + assert(bigIntComparisons(), "bigint values compare as signed integers"); + + print("done."); +}