[semfold] fix #19199; properly fold uint to float conversion (#19890) [backport]

fix #19199; properly fold float conversion
This commit is contained in:
flywind 2022-06-13 15:01:40 +08:00 • committed by GitHub
commit ab47707586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -409,7 +409,7 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P
rangeCheck(n, getInt(result), g) rangeCheck(n, getInt(result), g)
of tyFloat..tyFloat64: of tyFloat..tyFloat64:
case srcTyp.kind case srcTyp.kind
of tyInt..tyInt64, tyEnum, tyBool, tyChar: of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyBool, tyChar:
result = newFloatNodeT(toFloat64(getOrdValue(a)), n, g) result = newFloatNodeT(toFloat64(getOrdValue(a)), n, g)
else: else:
result = a result = a

6
tests/vm/t19199.nim Normal file
View file

@ -0,0 +1,6 @@
# bug #19199
proc mikasa(x: float) = doAssert x == 42
static:
mikasa 42.uint.float
mikasa 42.uint.float