Opened 9 months ago
Last modified 9 months ago
#3995 assigned Bug
Maps abort with negative integers as keys
Reported by: | anonymous | Owned by: | Jon |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | 3.3.16.1 | Severity: | None |
Keywords: | Cc: |
Description
Since the first time maps got introduced, the types supported as keys were Strings and Intigers, notably both positive and negative.
Now since version 3.3.15.2, the negative ints cause a hard crash with error "Variable subscript badly formatted."
This snippet works in 3.3.15.0 and 3.3.15.1 (and likely in earlier versions too), but crashes in all versions from 3.3.15.2 to 3.3.16.1
Global $m[] $m[12] = 'twelve' $m['-one'] = -1 $m[-2] = 'negative two' for $key in MapKeys($m) ConsoleWrite(VarGetType($key) &'->'& VarGetType($m[$key]) &' : '& $key &' = '& $m[$key] & @CRLF) next
In the working versions it will print this:
Int64->String : 12 = twelve String->Int32 : -one = -1 Int64->String : -2 = negative two
Attachments (0)
Change History (4)
comment:1 Changed 9 months ago by Jpm
comment:2 Changed 9 months ago by anonymous
I humble ask you to take another, fresh look at the maps, and see if the design truly cannot be improved just a wee little bit, to allow this USEFUL types as keys!
In fact, it seems any type that can be hashed can be possible to uee as key in maps; (and of course both negative and positive ints, floats, strings, pointers/handles, all these should be elementary to hash them...)
I have an extensive UDF library written in 3.3.15.0 for a client, (that i have used also for other clients later) that uses maps with negative integers as keys (namely, $GUI_EVENT* and such; for example $GUI_EVENT_CLOSE is -3), and also with GUI/Ctrl handles; and i used Default key to represent a default value that map should return if the key is not present in it. Now it seems, i cannot use this big library in any newer versions without rewriting it; which makes the clients frustrated and potentially angry and maybe very dangerous! That's... not ideal :)
comment:3 Changed 9 months ago by Jpm
- Owner set to Jon
- Status changed from new to assigned
It is easy to write $map[String(...)] = ...
But I leave to jon the decision to accept negative number
comment:4 Changed 9 months ago by Jpm
- Summary changed from Maps crash with negative integers as keys to Maps abort with negative integers as keys
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.
Hi, It is by design that negative number are not allowed
You also need to take care of conversion to int using ptr or handle that will do the same
I am not so sure that Doc is clear on this point.