fix VM uint conversion size bug, stricter int gen on JS (#22150)

* fix VM uint conversion bug, stricter int gen on JS

fixes #19929

* fix float -> uint64 conversion too

* no need to mask to source type

* simpler diff with explanation, add test for described issue
This commit is contained in:
metagn
2023-06-25 01:01:08 +03:00
committed by GitHub
parent c6c85f84db
commit f718f295df
5 changed files with 54 additions and 9 deletions

21
tests/js/tneginthash.nim Normal file
View File

@@ -0,0 +1,21 @@
# issue #19929
import std/[tables, hashes]
type Foo = object
a: int
proc hash(f: Foo): Hash =
var h: Hash = 0
h = h !& hash(f.a)
result = !$h
proc transpose[T, S](data: array[T, S]): Table[S, T] =
for i, x in data:
result[x] = i
const xs = [Foo(a: 5), Foo(a: -5)]
const x = transpose(xs)
doAssert x[Foo(a: -5)] == 1
doAssert x[Foo(a: 5)] == 0

View File

@@ -29,6 +29,9 @@ block hashes:
const wy123 = hashWangYi1(123)
doAssert wy123 != 0
doAssert hashWangYi1(123) == wy123
const wyNeg123 = hashWangYi1(-123)
doAssert wyNeg123 != 0
doAssert hashWangYi1(-123) == wyNeg123
# "hashIdentity value incorrect at 456"

View File

@@ -75,3 +75,10 @@ macro foo2() =
foo()
foo2()
block:
const neg5VM = block:
let x = -5'i8
uint64(x)
let y = -5'i8
doAssert uint64(y) == neg5VM