Modify

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: 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 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 11 years ago by Mat

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

comment:4 Changed 10 years ago by Jon

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

Fixed by revision [10658] in version: 3.3.13.15

comment:5 Changed 10 years ago by Jon

Fixed by revision [10659] in version: 3.3.13.15

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

Action
as closed The owner will remain Jon.
Author


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

 
Note: See TracTickets for help on using tickets.