From fbf9e94145c8e31156a160afe0e2d8de5233450e Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sun, 11 Aug 2024 23:31:17 +0800 Subject: [PATCH] fixes jsbigint64 regression; keeps convs to `Number` in danger mode (#23926) fixes jsbigint64 regression --- compiler/jsgen.nim | 8 +++++++- tests/js/tdanger.nim | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/js/tdanger.nim diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 157527989f..657994b0dd 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2632,7 +2632,13 @@ proc genRangeChck(p: PProc, n: PNode, r: var TCompRes, magic: string) = let src = skipTypes(n[0].typ, abstractVarRange) let dest = skipTypes(n.typ, abstractVarRange) if optRangeCheck notin p.options: - return + if optJsBigInt64 in p.config.globalOptions and + dest.kind in {tyUInt..tyUInt32, tyInt..tyInt32} and + src.kind in {tyInt64, tyUInt64}: + # conversions to Number are kept + r.res = "Number($1)" % [r.res] + else: + discard elif dest.kind in {tyUInt..tyUInt64} and checkUnsignedConversions notin p.config.legacyFeatures: if src.kind in {tyInt64, tyUInt64} and optJsBigInt64 in p.config.globalOptions: r.res = "BigInt.asUintN($1, $2)" % [$(dest.size * 8), r.res] diff --git a/tests/js/tdanger.nim b/tests/js/tdanger.nim new file mode 100644 index 0000000000..9088859a8a --- /dev/null +++ b/tests/js/tdanger.nim @@ -0,0 +1,17 @@ +discard """ + matrix: ";--d:danger" +""" + +block: + proc foo() = + var name = int64(12) + var x = uint32(name) + var m = x + 12 + + var y = int32(name) + var n = y + 1 + + doAssert m == uint32(n + 11) + + + foo()