Modify

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2551 closed Bug (No Bug)

if's and const's

Reported by: matthew.lagoe@… Owned by:
Milestone: Component: Au3Check
Version: 3.3.9.21 Severity: None
Keywords: Cc:

Description

When you put a global const in an if statement you get a previously declared as a 'Const' error

if @Compiled Then
	Global Const $configfile = @AppDataDir & "\X2Stor\config.ini"
Else
	Global Const $configfile = @ScriptDir & "\config.ini"
EndIf

Attachments (0)

Change History (8)

comment:1 Changed 11 years ago by Mat

As an aside, this is a very good example of when the beta's ?: ternary operator should now be the preferred method.

comment:2 Changed 11 years ago by Melba23

Firstly, that by definition is a variable and not a constant as its value is set at run time and is not fixed at compile time.

Secondly, you are not putting a Global Const into the script , you are putting two of them - and so the error is entirely justified.

Finally, good coding practice is to declare the variable before the condition check:

Global $configfile
If @Compiled Then
	$configfile = @AppDataDir & "\X2Stor\config.ini"
Else
	$configfile = @ScriptDir & "\config.ini"
EndIf

M23

Last edited 11 years ago by Melba23 (previous) (diff)

comment:3 Changed 11 years ago by Melba23

  • Resolution set to No Bug
  • Status changed from new to closed

comment:4 Changed 11 years ago by Melba23

I have just seem Mat's remark - good point:

Global $configfile = (@Compiled) ? (@AppDataDir & "\X2Stor\config.ini") : (@ScriptDir & "\config.ini")

M23

Version 0, edited 11 years ago by Melba23 (next)

comment:5 Changed 11 years ago by anonymous

is it worth to mention that the provided examples are working without errors in AutoIt 3.3.9.23

And even when the variable is declared as a Const!

Global Const $c = ((@Compiled)?(@AppDataDir&"\fldr"):(@ScriptDir))&"\yay!.ini"
ConsoleWrite($c &@LF)
if @Compiled Then
	Global Const $configfile = @AppDataDir & "\X2Stor\config.ini"
Else
	Global Const $configfile = @ScriptDir & "\config.ini"
EndIf
ConsoleWrite($configfile &@LF)

both working like charm.

re. Melba23
Secondly, you are not putting a Global Const into the script , you are putting two of them - and so the error is entirely justified.

Justified? Not by those reasons, nope. The error is only intuitively to be expected when there is an attempt to redeclare or otherwise assign a value to a var, that was already declared before as a Const.

In examples above, neither of the vars is written-into, or declared, twice. Therefore, no error, and none should be.

comment:6 Changed 11 years ago by anonymous

I was not clear in my comments and I believe you are confusing AutoIt and Au3Check.

AutoIt itself has no problem with your originally posted construct in either 3.3.8.1 or the Beta. The error is flagged up by the Au3Check syntax checking tool. Its logic is pretty simple and as far as it is concerned you are indeed declaring the same constant twice - so it fires off an error. This happens regardless of the version used and it is not reasonable to expect Au3Check to check if the declaration is within a conditional statement - it is complex enough already.

M23

Last edited 11 years ago by Melba23 (previous) (diff)

comment:7 Changed 11 years ago by Mat

is there any way to manually tell au3check then to ignore the error, as au3check stops the program from being able to be ran etc from in scite.

comment:8 Changed 11 years ago by guinness

No there isn't. Well there is #AutoIt3Wrapper_Run_Au3Check=N, but I don't think that's what you're looking for.

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

Action
as closed The ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.