possible issue with GetCapacity?

Report problems with documented functionality
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

possible issue with GetCapacity?

10 Jun 2017, 04:56

Code: Select all

q:: ;test GetCapacity
v1 := 3
v2 := "3"

;work fine
MsgBox, % ObjGetCapacity([v1], 1) "_" ObjGetCapacity([v2], 1)
MsgBox, % ObjGetCapacity([v2], 1) "_" ObjGetCapacity([v1], 1)

;work fine
MsgBox, % [v1].GetCapacity(1)
MsgBox, % [v2].GetCapacity(1)
MsgBox, % ObjGetCapacity([v1], 1)
MsgBox, % ObjGetCapacity([v2], 1)

;doesn't work as expected
MsgBox, % [v2].GetCapacity(1) "_" [v1].GetCapacity(1)
;this still works
MsgBox, % [v2].GetCapacity(1)

;doesn't work as expected
MsgBox, % [v1].GetCapacity(1) "_" [v2].GetCapacity(1)
;now returns blank:
MsgBox, % [v2].GetCapacity(1)
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 7141
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: possible issue with GetCapacity?

10 Jun 2017, 05:21

Seems to be some kind of 'auto-concat' feature:

Code: Select all

; q:: ;test GetCapacity
v1 := 3
v2 := "3"

;work fine
MsgBox, % ObjGetCapacity([v1], 1) "_" ObjGetCapacity([v2], 1)
MsgBox, % ObjGetCapacity([v2], 1) "_" ObjGetCapacity([v1], 1)

;work fine
MsgBox, % [v1].GetCapacity(1)
MsgBox, % [v2].GetCapacity(1)
MsgBox, % ObjGetCapacity([v1], 1)
MsgBox, % ObjGetCapacity([v2], 1)

;doesn't work as expected - this does
MsgBox, % [v2].GetCapacity(1) . "_" . [v1].GetCapacity(1)
;this still works
MsgBox, % [v2].GetCapacity(1)

;doesn't work as expected - this does
MsgBox, % [v1].GetCapacity(1) . "_" . [v2].GetCapacity(1)
;now returns blank: - no
MsgBox, % [v2].GetCapacity(1)
return
lexikos
Posts: 6962
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: possible issue with GetCapacity?

10 Jun 2017, 06:15

It's not auto-concat.

"_" [v1] does not create an array. It is the same as "_"[v1] or SomeVariable[v1] when SomeVariable contains "_". This is not a bug.

I'm not sure about "now returns blank:".

Edit: That's also not a bug, and part of the reason I did not port type() to v1.

Code: Select all

v2 := "3"
MsgBox % {} [v2]  ; Same effect as "_" [v2]
MsgBox % [v2].GetCapacity(1)
When you index into an object, numeric strings are converted to numbers. When such conversions are made in v1, the number is cached to enhance performance. v1 is not designed to preserve the "type" of the value.

"_" [v2] has the same effect because it implicitly indexes into the default base object ("_".base):

Code: Select all

"".base[3] := "foo"
v2 := "3"
MsgBox % "_" [v2]
Most other expressions which use the variable as a number have the same effect.

Code: Select all

v2 := "3"
MsgBox % v2 = 0  ; v2+0, v2*1, etc.
MsgBox % [v2].GetCapacity(1)
just me
Posts: 7141
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: possible issue with GetCapacity?

11 Jun 2017, 05:03

lexikos wrote:It's not auto-concat.
One reason more not to omit the concat operator . if you intend to concatenate and don't want 'unexpected results'. ;)

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests