Page 1 of 1

Potential Syntax Flaw AHKv1- Please evaluate importance

Posted: 21 Jul 2020, 10:56
by julesverne

Code: Select all

Julesverne := "hello"

;incorrect elseif syntax <- no space between else and if on line #7, which is very possibly overlooked by the author.
;with open start bracket on the same line #7 this will properly throw a compilation error
If (Julesverne = "hello"){
	msgbox, % "this message should appear Example 1."
} elseif (Julesverne = "helo"){
	msgbox, % "this message shouldn't appear Example 1."
}
by Contrast Example 2

Code: Select all

Julesverne := "hello"

;incorrect elseif <- no space between else and if on line #7, which is very possibly overlooked by the author.
;with open start bracket on the next line #8 this will not have a run time error, because it doesn't get evaluated, which would confuse the author as to why he was seeing the msgbox appear in line #9
If (Julesverne = "hello"){
	msgbox, % "this message should appear Example 2."
} elseif (Julesverne = "helo")
{
	msgbox, % "this message shouldn't appear Example 2."
}
Example 2 DOES correctly throw an Error in AHK v2, so for now this *issue* is only relegated to v1.

The potential for this being a problem for instance may come from devs who write vbscript (like myself) where the correct syntax is ElseIf, so to me, Example 2 looks like it should work correctly. Especially when it doesn't throw an error telling me that syntax is incorrect.

Re: Potential Syntax Flaw AHKv1- Please evaluate importance

Posted: 21 Jul 2020, 12:10
by boiler
It's not a syntax error. If you use the #Warn directive, you'll see you have an undeclared variable elseif. You just have an expression sitting there doing nothing. It's the variable elseif concatenated with the boolean result of (Julesverne = "helo"). It can be run as a do-nothing stand-alone script:

Code: Select all

elseif (Julesverne = "helo")
You can assign contents to the variable elseif and display it and the boolean result:

Code: Select all

Julesverne := "hello"
elseif := "Does Julesverne contain 'helo'?: "

;incorrect elseif <- no space between else and if on line #7, which is very possibly overlooked by the author.
;with open start bracket on the next line #8 this will not have a run time error, because it doesn't get evaluated, which would confuse the author as to why he was seeing the msgbox appear in line #9
If (Julesverne = "hello"){
	msgbox, % "this message should appear Example 2."
} msgbox % elseif (Julesverne = "helo")
{
	msgbox, % "this message shouldn't appear Example 2." ; yes it should
}
For that to be reported as an error would be to say that elseif should be reserved and not available as a variable name.