Modify

#4103 new Bug

The expression in the array index was evaluated twice when assigning value

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

Description

Example code:

Local $i = -1
Func Inc()
	$i += 1
	ConsoleWrite("$i = " & $i & @CRLF)
	Return $i
EndFunc

Local $a[5] = [0, 1, 2, 3, 4]
$a[Inc()] = "Test"
_DebugArrayDisplay($a, $i)

The result in console:

$i = 0
$i = 1

The result of array display:

Row|Col 0
# 0|0
# 1|Test
# 2|2
# 3|3
# 4|4

The result of $i: 1

This bug only occurs when assigning value to the array ($a[Inc()] = "value"), but not when getting value ($value = $a[Inc()])

Attachments (0)

Change History (1)

comment:1 by Jpm, on Jun 10, 2026 at 2:43:25 PM

You right I remember similar pb
at that time the answer will not be fix due to the way the the interpreter is evaluating the subscript for array entry assignment

just change $a[Inc()] = "Test"
to
$i=Inc()
$a[$i] = "Test"

Modify Ticket

Action
as new The ticket will remain with no owner.

Add Comment


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