Modify

#3581 closed Bug (Wont Fix)

Dot notation with DllStruct fails if the variable is a constant

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

Description

The code below illustrates the problem

#AutoIt3Wrapper_Run_Au3Check=N
Global Const $tStruct = DllStructCreate("BYTE a")

Works()
Fails()

Func Works($tStruct = $tStruct)
    $tStruct.a = 1
EndFunc

Func Fails()
    $tStruct.a = 1
EndFunc

Output

"D:\Desktop\tmp.au3" (12) : ==> Cannot assign values to constants.:
$tStruct.a = 1
^ ERROR

Attachments (0)

Change History (5)

comment:1 by Jos, on Jan 7, 2018 at 10:51:07 AM

What exactly is the issue with getting a warning when trying to change a constant?

Jos

comment:2 by genius257, on Jan 7, 2018 at 3:58:58 PM

I'm not changing the constant, but a property of the constant.
If it should fail, so should DllStructSetData($tStruct, "a", 1)

comment:3 by Jos, on Jan 7, 2018 at 8:26:35 PM

The left $tStruct in Func Works is a local declared variable for Func Works and it act like doing it this way:

Global Const $tStruct = DllStructCreate("BYTE a")

Works()
Fails()

Func Works($x = $tStruct)
    $x.a = 1
EndFunc

Func Fails()
    $tStruct.a = 1
EndFunc

So $tStruct in Func works is not the Global declared one but a Local new variable.

Jos

Version 2, edited on Jan 7, 2018 at 9:05:07 PM by Jos (previous) (next) (diff)

comment:4 by genius257, on Jan 8, 2018 at 6:57:42 PM

I can't seem to find any details about how a constant in AutoIt is treated other than the value of a constant cannot be changed.

But currently AutoIt allows properties to be changed in constant variables if for instance it's a DllStruct and DllStructSetData is used. This is like ES6 when defining a const with a object value. Properties of the object can still be changed. The only thing that's immutable is the binding source.

If AutoIt is not supposed to act like my example with ES6, then AutoIt should not allow DllStructSetData to work with a constatnt variable as it's first parimeter.

If on the other hand the ES6 example is the case, then AutoIt should allow properties of const variables to be changed when using dot notation.

I hope I've made myself understandable and that you see the current way it works is a bug one way or the other?

comment:5 by Melba23, on Jan 30, 2018 at 10:15:43 AM

Resolution: Wont Fix
Status: newclosed

Dot notation for structs is an undocumented feature and so bug reports about the feature are not supported. Use DllStructSetData instead.

M23

Modify Ticket

Action
as closed 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.