Opened 4 months ago

Last modified 6 weeks ago

#3943 reopened Bug

Using a function return to increment an counter array element causes TWO function calls

Reported by: RTFC Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: array index function call Cc:


When a function call yields an index that is used directly to increment an array element, the function is called twice!

Global $size=5
Global $array[$size]

consolewrite( "standalone call yields: " & _GetRandomIndex($size-1) & @CRLF & @CRLF)
consolewrite( "array index call + increment yields two calls?!" & @CRLF)


Func _GetRandomIndex($maxindex)
	ConsoleWrite("func called" & @CRLF)
	Return Random(0,$maxindex,1)

Attachments (0)

Change History (6)

comment:1 Changed 4 months ago by anonymous

Presumably this affects all compound operators, not just +=
The solution would be to not blindly expand A[x]+=y to A[x]=A[x]+y but first capturing x in a temporary.

comment:2 Changed 4 months ago by pixelsearch

For what it's worth, the related issue appeared for the 1st time with AutoIt version

#include <Array.au3>

Local $array[5]
$array[_F()] = "hello"

Func _F()
        ConsoleWrite("func called" & @CRLF) ; once with , twice with
        ; implicit Return 0

2012 - AutoIt => 1 call (tested)
2013 - AutoIt => 2 calls (tested)

comment:3 Changed 6 weeks ago by Jpm

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

Fixed by revision [12983] in version:

comment:4 Changed 6 weeks ago by Jpm

  • Resolution Fixed deleted
  • Status changed from closed to reopened

comment:5 Changed 6 weeks ago by Jpm

Badly closed

comment:6 Changed 6 weeks ago by TicketCleanup

  • Milestone deleted

Automatic ticket cleanup.

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 reopened The owner will remain Jpm.

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

Note: See TracTickets for help on using tickets.