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 jchd18, on Oct 13, 2013 at 11:58:30 PM

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 by Tasiro, on Oct 14, 2013 at 1:12:25 AM

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 Matt Diesel, on May 20, 2014 at 11:15:05 PM

Further discussed in ticket #2713, and on the MVP forum here: http://www.autoitscript.com/forum/topic/161296-supposed-byref-bug/

comment:4 by Jon, on Aug 4, 2014 at 12:32:02 PM

Milestone: 3.3.13.15
Owner: set to Jon
Resolution: Fixed
Status: newclosed

Fixed by revision [10658] in version: 3.3.13.15

comment:5 by Jon, on Aug 4, 2014 at 1:38:21 PM

Fixed by revision [10659] in version: 3.3.13.15

Modify Ticket

Action
as closed The owner will remain Jon.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.