Modify ↓
#2502 closed Bug (Fixed)
COW optimization incorrect
| Reported by: | Tasiro | Owned by: | Jon |
|---|---|---|---|
| Milestone: | 3.3.13.15 | Component: | AutoIt |
| Version: | 3.3.9.21 | Severity: | None |
| Keywords: | Cc: |
Description
Local $arr1 [1] = [1] rest ($arr1 [0]) ; create a reference Func rest (ByRef $element) ; with a complicated syntax Local $arr2 = $arr1 ; copy the array MsgBox (0, "", $arr1 [0] & @CRLF & $arr2 [0]) ; 1 / 1 $element = 10 ; modify the value in $arr1 MsgBox (0, "", $arr1 [0] & @CRLF & $arr2 [0]) ; 10 / 10 ; > "What? But I copied my array $arr1 after the modification..." ; Poor programmer... EndFunc
Too bad there are references.
See http://www.gotw.ca/gotw/044.htm.
Attachments (0)
Change History (5)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
ByRef applies to r-values too, as you can see in the example, and it is effective. But the result is unexpected, why can I modify a copy of an array with a reference to an element of the copied array? The expected second output would be "10 / 1".
The link describes a solution to that problem.
comment:3 by , 12 years ago
Further discussed in ticket #2713, and on the MVP forum here: http://www.autoitscript.com/forum/topic/161296-supposed-byref-bug/
comment:4 by , 12 years ago
| Milestone: | → 3.3.13.15 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [10658] in version: 3.3.13.15
Note:
See TracTickets
for help on using tickets.

The error in the above reasonning is that AutoIt != C++. While the documentation (correctly) says that ByRef can be applied to the result of an expression, it should clearly state that ByRef is ineffective in that case.
Probably this ticket should be directed to "Documentation" with the complain that ByRef only applies to named variables.