Opened 10 years ago
Last modified 8 months ago
#2855 assigned Feature Request
Scoping and declaration modifiers combinations
Reported by: | jchd18 | Owned by: | Jon |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | Severity: | None | |
Keywords: | Cc: |
Description
Static is currently forbidden in combination with Enum and Const but these that can be needed in the real world.
Dim $a1 Local $a2 Global $a3 Static $a4 Local Static $a5 Global Static $a6 Enum $a7 Dim Enum $a8 Local Enum $a9 Global Enum $a10 ;~ Static Enum $a11 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Local Static Enum $a12 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Global Static Enum $a13 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. Const $a14 = 0 Dim Const $a15 = 1 Local Const $a16 = 2 Global Const $a17 = 3 ;~ Static Const $a18 = 4 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Local Static Const $a19 = 5 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Global Static Const $a20 = 6 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. Const Enum $a21 Dim Const Enum $a22 Local Const Enum $a23 Global Const Enum $a24 ;~ Static Const Enum $a25 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Local Static Const Enum $a26 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement. ;~ Global Static Const Enum $a27 ; ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement.
Static Enum and Static Const (Local or Global) are useful to allow skipping subsequent lengthy or "runonce" initialization (e.g. having side-effects).
<*> Const Enum are harmless redondancies since Enums are constant, so Static Const Enum (Local or Global) should work as well.
BTW what is this "Struct" statement mentionned in the error message? (It is also recognized as a keyword in SciTE.)
Attachments (0)
Change History (13)
comment:1 Changed 10 years ago by TicketCleanup
- Version 3.3.12.0 deleted
comment:2 Changed 10 years ago by anonymous
agree. Especially lacking Local Static Const
comment:3 Changed 10 years ago by jchd18
Of course this one, yet Local Static Const Enum might be required as well as some others. All combinations even if less useful or meaningful would be welcome, just for symetry and denoting intention.
Only contradictory (Local Global $a) or badly formed (Global Const Static $a) should be denied.
comment:4 Changed 10 years ago by Jpm
I still hate the Local being Global when declares in the main script ...
comment:5 Changed 10 years ago by jchd18
Lacking file scope I still find it valuable as a hint of the intended scope, albeit in practice it can be subverted as if it were global. But this is a completely distinct matter.
BTW JP, do you have the faintest idea about "Struct"? Was that a typo for "Static" or something left over from very old versions?
comment:6 Changed 10 years ago by anonymous
Where would a Static Constant ever be used, and for what? If it's a constant, there's no need to use Static because you can set it once at the beginning of a function and never have to worry about what it is the next time you run your function. Static only allows the contents of a variable to remain valid after the function ends, and then is visible again after the function is called again.
Also, Global Static is completely pointless.
comment:7 Changed 10 years ago by jchd18
You forget the case where a constant initialization is not a literal or an expression with fixed value but the result of a computation with side-effect or randomization. If you don't tag it with Static, you'll go thru initialization again at every invokation of the function, and the constant will have a new value every time (or cause other nasty side-effect, depending on context).
Some other combinations could be allowed even if semantically pointless, just to denote intent.
comment:8 Changed 4 years ago by mLipok
For clarify and refresh - example:
#AutoIt3Wrapper_Run_Au3Check=N _Example() _Example() _Example2() _Example2() Func _Example() Local $hTimer = TimerInit() Local Const $bTest = _Initialize_Variable() Local $fDiff = TimerDiff($hTimer) ConsoleWrite("Time Difference Test1 = " & $fDiff & @CRLF) EndFunc Func _Example2() Local $hTimer = TimerInit() Local Static $bTest1 = _Initialize_Variable() Local Const $bTest2 = $bTest1 Local $fDiff = TimerDiff($hTimer) ConsoleWrite("Time Difference Test2 = " & $fDiff & @CRLF) EndFunc Func _Initialize_Variable() ; do some stuff ; for example read some data from XLS or from CSV or any other type of database Return Sleep(1000) EndFunc
comment:9 Changed 4 years ago by Jpm
- Owner set to Jpm
- Status changed from new to assigned
Fix sent to Jon
comment:10 Changed 17 months ago by anonymous
#AutoIt3Wrapper_Run_Au3Check=N
_Example()
_Example()
_Example2()
_Example2()
Func _Example()
Local $hTimer = TimerInit()
Local Const $bTest = _Initialize_Variable()
Local $fDiff = TimerDiff($hTimer)
ConsoleWrite("Time Difference Test1 = " & $fDiff & @CRLF)
EndFunc
Func _Example2()
Local $hTimer = TimerInit()
Local Static $bTest1 = _Initialize_Variable()
Local Const $bTest2 = $bTest1
Local $fDiff = TimerDiff($hTimer)
ConsoleWrite("Time Difference Test2 = " & $fDiff & @CRLF)
EndFunc
Func _Initialize_Variable()
; do some stuff ; for example read some data from XLS or from CSV or any other type of database
Return Sleep(1000)
EndFunc
comment:11 Changed 9 months ago by Jpm
I found that my fix was not so good,
I have difficulty for the Static Local Enum ...
Can I forget about it?
comment:12 Changed 9 months ago by Andreik
Static Local Enum might be handy in some situations but if this is the only scoping declaration with issues, can others be implemented and delay this one until you have a proper fix? By the way, are there any other developers helping you with the huge amount of requests?
comment:13 Changed 8 months ago by Jpm
- Owner changed from Jpm to Jon
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.
Automatic ticket cleanup.