Possible Bug: object with numeric key in v2.0-a095-9f724c5 Topic is solved

Discuss the future of the AutoHotkey language
User avatar
aseiot
Posts: 11
Joined: 05 Mar 2017, 04:25

Possible Bug: object with numeric key in v2.0-a095-9f724c5

Post by aseiot » 29 Apr 2018, 07:07

Code: Select all

F := {"-2146826281" : "ANYTHING"}
MsgBox F["-2146826281"]	; SHOW EMPTY STRING
MsgBox F[-2146826281]	; Cause AHK CRASH
User avatar
aseiot
Posts: 11
Joined: 05 Mar 2017, 04:25

Re: Possible Bug: object with numeric key in v2.0-a095-9f724c5

Post by aseiot » 02 May 2018, 00:43

Did more test about the numeric key of object.
v2-changes wrote:Integer constants and numeric strings outside of the supported range (of 64-bit signed integers) now overflow/wrap around, instead of being capped at the min/max value. This is consistent with math operators, so 9223372036854775807+1 == 9223372036854775808 (but both produce -9223372036854775808).
And I found some inconsistent results:

Code: Select all

MsgBox 9223372036854775807+1 == 9223372036854775808	; "1" as expected
MsgBox 9223372036854775808	; "-9223372036854775808" as expected
O := {}
O["9223372036854775808"] := "ANYTHING"
MsgBox O["9223372036854775808"]	; "ANYTHING" as expected
MsgBox O["-9223372036854775808"] ; Empty String as expected

for k, v in O
	MsgBox k "," v	; "9223372036854775808,ANYTHING" as expected

O := {}
O[9223372036854775808] := "ANYTHING"
MsgBox O[9223372036854775808]
MsgBox O[-9223372036854775808]
MsgBox O["9223372036854775808"]

; We got three different results when run the code repeatly!

; 1:
; Nothing,Nothing,Nothing

; 2:
; Nothing,"ANYTHING",Nothing

; 3:
; "ANYTHING","ANYTHING",Nothing

for k, v in O
	MsgBox k "," v	; "-9223372036854775808,ANYTHING" as expected
So I anticipate the O["9223372036854775808"] do not auto convert to O[9223372036854775808], so treated it as string key?

Another test:

Code: Select all

O := {}
O[100] := "ANYTHING"
MsgBox O[100]	; "ANYTHING"
MsgBox O["100"]	; "ANYTHING"
"100" is converted to 100? I got an explanation in v2-changes
v2-changes wrote:As of v2.0-a067, numeric strings are converted to pure integers where possible without causing the kind of data loss described above.
Back to my preview problem:

Code: Select all

; Crashed sometimes with Exit code: 3221225477. 

F := {"-2146826281" : "ANYTHING"}
MsgBox F["-2146826281"]	; SHOW EMPTY STRING
MsgBox F[-2146826281]	; SHOW EMPTY STRING

for k, v in F
	MsgBox k "," v	; "-2146826281,ANYTHING" as expected.
So, above all, my question is the correct ways to set and get the key and value consistently in object?
User avatar
nnnik
Posts: 3326
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Possible Bug: object with numeric key in v2.0-a095-9f724c5

Post by nnnik » 02 May 2018, 00:51

Yes it is - this might relate to a recent change in the AutoHotkey source.
I'm sure someone will look into it in time.
Recommends AHK Studio
lexikos
Posts: 6172
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Possible Bug: object with numeric key in v2.0-a095-9f724c5  Topic is solved

Post by lexikos » 07 May 2018, 06:28

Fixed in v2.0-a096.
User avatar
aseiot
Posts: 11
Joined: 05 Mar 2017, 04:25

Re: Possible Bug: object with numeric key in v2.0-a095-9f724c5

Post by aseiot » 07 May 2018, 09:07

Thanks
Post Reply

Return to “AutoHotkey v2 Development”