fixes jsbigint64 regression; keeps convs to Number in danger mode (#23926)

fixes jsbigint64 regression
This commit is contained in:
ringabout
2024-08-11 23:31:17 +08:00
committed by GitHub
parent b9b24e192a
commit fbf9e94145
2 changed files with 24 additions and 1 deletions

View File

@@ -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]

17
tests/js/tdanger.nim Normal file
View File

@@ -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()