Jump to content
Sign in to follow this  
dudu5962

is this a bug ?

Recommended Posts

dudu5962

hi all,

i know this kind of code is really bad but when compiling everything seems great, i mean there's no error

but if you run the exe (launching the script will exit abnormaly but it is a bit hard to see in my example) it will say that $var is used without being declared

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("MustDeclareVars", 1)

If(0) Then
    Local $var = 0
    MsgBox(0, "", $var)
Else
    MsgBox(0, "", $var)
EndIf

i understand why and i m not looking for how to make it work, for me it is a bug ... need to be reported

Share this post


Link to post
Share on other sites
Jos

When the IF is not true the Local statement is not executes thus an error occurs.

The compiler and au3check cannot figure this out since the code needs to be executed for this error to occur.

the code should be:

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("MustDeclareVars", 1)

Local $var = 0
If(0) Then
    MsgBox(0, "", $var)
Else
    MsgBox(0, "", $var)
EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
dudu5962

i think the "mustdeclarevars" should warn me

the if statement is not well managed with that

Share this post


Link to post
Share on other sites
czardas

I think that there are so many possible ways to do things with autoit that it is very difficult to predict all types of error. If you tried to use the variable, I'm pretty sure that it would throw this error. The code you posted doesn't do anything with the variable, so there was no error.

Edit: I misunderstood. It does throw an error when I run your code.

Edited by czardas

Share this post


Link to post
Share on other sites
Jos

i think the "mustdeclarevars" should warn me

the if statement is not well managed with that

Great, but it is not a bug but a programmers error!

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
dudu5962

Great, but it is not a bug but a programmers error!

In a way i agree with you, writting this is really bad

what makes me think it s a bug is that by using "mustdeclarevars" it gives you error anytime you use vars without being declared.

In the else statement it is not and it makes the program stop with an error. So in a way the compiler miss this error. it doesn't managed the if statement as it is executed

(i must have made english error as it is not my language)

Share this post


Link to post
Share on other sites
Jos

In a way i agree with you, writting this is really bad

what makes me think it s a bug is that by using "mustdeclarevars" it gives you error anytime you use vars without being declared.

In the else statement it is not and it makes the program stop with an error. So in a way the compiler miss this error. it doesn't managed the if statement as it is executed

(i must have made english error as it is not my language)

The compiler only checks syntax (lexing) but does not run the script thus will never be able to detect a LOCAL statement being in the wrong place.

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.