uiua-lang / uiua

A stack-based array programming language
https://www.uiua.org
MIT License
1.62k stars 117 forks source link

map insert produces duplicate keys #606

Open Defelo opened 1 week ago

Defelo commented 1 week ago

This does not seem to happen on Uiua Pad, but at least in the native interpreter on x86_64-linux (commit 743ec318ea0dff1e7b79d6bf6953161fbc802d67).

Example:

map {"x" "y" "z"} [1 2 3]
remove □"y"
insert □"z" 4 .
⟜°map .
⍣(insert □"a" 17|◌)

Output:

╭─
  ⌜x⌟ → 1
  ⌜z⌟ → 3
          ╯
╭─
  ⌜x⌟ → 1
  ⌜z⌟ → 4
  ⌜z⌟ → 4
          ╯
[1 4]
{"x" "z" "z"}
"test.ua:5:3: Cannot insert into map with 3 keys and 2 value(s)"
Defelo commented 1 week ago

Hi @kaikalii, thanks for taking a look at this so quickly! While this specific test case now seems to work, I unfortunately found some more problems:

map [0 0 1] [1 2 3]
°map

Output:

[1 2 3]
[0 1]

So again, we have a map where the number of keys and values differ and thus inserting and removing fail.

Apart from that I also found a second (larger) test case which starts with a valid map and breaks it using remove and insert:

{"hlvq" "xvng" "tv" "sgnr" "rdnp" "bxlh" "ktcxx" "jg" "fm" "lxccq" "fnztg" "zsp" "cc" "vbl" "dk" "tsrjk" "xrzx" "zh" "qvq" "dp" "sh" "jfvnl" "lq" "nnnrz" "zzl" "kmsq"}
map ⟜(⇡⧻)
remove "zh"
insert "kmsq" 0
∩⧻°map

Output:

25
26

In this case the key "kmsq" is duplicated, so now we have a map with 26 keys but only 25 values.

(tested on commit 3bf1ff3c14610e050c1747db8ba9f623c3dc8c3d)

kaikalii commented 1 week ago

This should be fixed in 0fce8a1fbf63ff5c593052. Let me know if you find any others!

Defelo commented 1 week ago

@kaikalii I think I found another one. This time the program doesn't terminate at all (which unfortunately also causes the vscode extension to not respond anymore):

map {"a" "b" "c"} [1 2 3]
remove "b"
insert "d" 4
insert "e" 42
kaikalii commented 6 days ago

Fixed in 156d82b963fb8f6d0332e1add. I'm going to leave this issue open for a while just in case.