Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#2502 closed Bug (Fixed)

COW optimization incorrect

Reported by: Tasiro Owned by: Jon
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


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...

Too bad there are references.

Attachments (0)

Change History (5)

comment:1 Changed 11 years ago by jchd18

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.

comment:2 Changed 11 years ago by Tasiro

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 Changed 10 years ago by Mat

Further discussed in ticket #2713, and on the MVP forum here:

comment:4 Changed 10 years ago by Jon

  • Milestone set to
  • Owner set to Jon
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [10658] in version:

comment:5 Changed 10 years ago by Jon

Fixed by revision [10659] in version:

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.

Add Comment

Modify Ticket

as closed The owner will remain Jon.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.