Jump to content

is this a bug ?


Recommended Posts

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developers

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!

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

  • Developers

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.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...