Opened 11 years ago
Last modified 10 years ago
#2713 closed Bug
ByRef Copy Bug — at Initial Version
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.11.5 | Severity: | None |
| Keywords: | byRef | Cc: |
Description
In the following script, the presence of ByRef causes $old to be a reference, not a copy.
#include "car.au3" $car = Car () ; speed: 50 Func getAcceleratedCar (ByRef $car_speed) Local $old = $car $car_speed *= 2 Local $new = $car Car_printSpeed ($car, "car") ; speed: 100 Car_printSpeed ($old, "old") ; speed: 100, expected 50 Car_printSpeed ($new, "new") ; speed: 100 $car = $old return $new EndFunc getAcceleratedCar ($car [$Car_Speed])
car.au3:
; class Car
Func Car ($speed = 50)
Local $__instance [$__Car__ObjectSize] = [$__Car__VTable]
$__instance [$Car_Speed] = $speed
return $__instance
EndFunc
Func __Car__printSpeed__Impl (ByRef $__instance, $name)
ConsoleWrite ("speed of " & $name & ": " & $__instance [$Car_Speed] & @CRLF)
EndFunc
Func Car_printSpeed (ByRef $__instance, $__arg1)
Local $function = ($__instance [$__Car__VTableIndex]) [$__Car__printSpeed__Index]
Return $function ($__instance, $__arg1)
EndFunc
Const $__Car__VTableIndex = 0
Const $__Car__VTable = [__Car__printSpeed__Impl]
Const $__Car__printSpeed__Index = 0
Const $__Car__ObjectSize = 2
Const $Car_Speed = 1
; end class Car
Note: See
TracTickets for help on using
tickets.
