Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutating a mutable dictionary key causes weird behaviour (instead of an error.) #79626

Open
ghost opened this issue Jul 18, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 18, 2023

Godot version

v4.1.1.stable.official.bd6af8e0e

System information

Windows 10.0.19045 - Vulkan (Compatibility) - GeForce GT 540M- Intel Core i7-2670QM CPU @ 2.20GHz (8 Threads)

Issue description

When a dictionary is made with a mutable key, for example:

var x = [1, 2, 3]
var test = {x: "cat"}

And then then the key is mutated:

x[2] = 4

Weird behaviour can be observed:

print(test)
print(test[x])
print(test[[1,2,4]])

Returns:

{[1, 2, 4]: <null>}
<null>
<null>

Instead of:

{[1, 2, 4]: "cat"}
"cat"
"cat"

Even though:

print(test.find_key("cat"))

Works correctly:

[1, 2, 4]

 
 
 
For reference in Python:

test = {[1, 2, 3]: "cat"}

Is:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    test = {[1, 2, 3]: "cat"}
TypeError: unhashable type: 'list'

Steps to reproduce

  1. Use the minimal reproduction project.
  2. Run the project.
  3. Observe the bug.

Minimal reproduction project

Mutable-Dictionary-Key-4.1.1-Test.zip

@AcatXIo
Copy link
Contributor

AcatXIo commented Aug 18, 2023

I can confirm the issue for version v4.2.dev3.official.013e8e3af.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants