Opened 22 months ago
Last modified 10 months ago
#3948 assigned Bug
Map object: keys [0] and ["["] clash
Reported by: | Simon E. <autoitscript.com@…> | Owned by: | Jon |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | 3.3.16.1 | Severity: | None |
Keywords: | maps, keys | Cc: |
Description
Hi team,
I realise that map objects are experimental and bug reports are not wanted, but I just thought I'd record this here in case anyone is interested.
When a map object contains a key of 0 and a key of [ these seem to clash in some way and tend to overwrite each other. But somewhat intermittently.
Here's an example script:
Local $map[] $map["a"] = 1 $map["0"] = 2 $map[0] = 3 $map["["] = 4 ConsoleWrite($map["a"] & @CRLF) ; expecting 1 ConsoleWrite($map["0"] & @CRLF) ; expecting 2 ConsoleWrite($map[0] & @CRLF) ; expecting 3, but sometimes prints 4 ConsoleWrite($map["["] & @CRLF) ; expecting 4 $map[0] = 5 ConsoleWrite($map[0] & @CRLF) ; expecting 5 ConsoleWrite($map["["] & @CRLF) ; expecting 4, but sometimes prints 5
When running this script, I would expect the console to show:
1 2 3 4 5 4
This happens intermittently, on about 40% of executions. On the other 60%, I get this result instead, where any assignment to $map[0] and $map["["] ends up overwriting each other:
1 2 4 4 5 5
I suspect that somehow, internally, 0 and [ are assigned the same value, resulting in the clash.
I uncovered this while trying to create a map of various characters and their binary representations. One workaround is to ensure the keys are all strings, and not use integer keys. It was a confusing bug for a while, though.
Attachments (0)
Change History (2)
comment:1 Changed 10 months ago by Jpm
- Owner set to Jpm
- Status changed from new to assigned
comment:2 Changed 10 months ago by Jpm
- Owner changed from Jpm to Jon
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Fix sent to Jon