summary refs log tree commit diff stats
path: root/tests/js/tneginthash.nim
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-06-25 01:01:08 +0300
committerGitHub <noreply@github.com>2023-06-25 00:01:08 +0200
commitf718f295df3f6ee5d7fd6fc19e39ac663821b00a (patch)
tree3ed631793cd2d838ad4909afa51770b28864cb14 /tests/js/tneginthash.nim
parentc6c85f84db3bd7bd2d1c5823020c7df007f1bb69 (diff)
downloadNim-f718f295df3f6ee5d7fd6fc19e39ac663821b00a.tar.gz
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
Diffstat (limited to 'tests/js/tneginthash.nim')
-rw-r--r--tests/js/tneginthash.nim21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/js/tneginthash.nim b/tests/js/tneginthash.nim
new file mode 100644
index 000000000..c082405c9
--- /dev/null
+++ b/tests/js/tneginthash.nim
@@ -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
f='#n2'>2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27