XojoScript warnings do not specify locations within the line.

The new XojoScript is a significant improvement over RBScript, but it still has some unexpected behavior with regard to error/warning reporting. Although error messages pinpoint the error within the line, warnings only give the line in which they occur. Is this a known problem?

Using the supplied XojoScript program (in examples/advanced), if one enters the following program:

sub blim()
dim a,b,c as integer
end sub

dim a,b,c as integer
dim i,j as integer
dim c as integer

when Run button is pressed, you get the following warnings and error messages:

W [2:-1-2:-1] This local variable is unused.
W [2:-1-2:-1] This local variable is unused.
W [2:-1-2:-1] This local variable is unused.
E [7:4-7:5] Duplicate identifier.

Where the letters W and E refer to the colored icons. You can indeed open the triangle associated with the warnings to find which local variable is referenced, but the warning only gives the first position of the line. It would be nice if the information for the warnings and the errors were at an identical level.

Sort of. It’s not a matter of warnings versus errors, just a matter of what information the compiler gives back. The compiler only records the line a declaration came from and not the exact range in that line. When the compiler triggers the warning about the variable being unused, the line is all it has to offer.

You can see the same situation with GoTos that are missing their labels. It highlights the function declaration because it records that a label was used but not the exact line the GoTo was on.

Thanks for the clarification. But somehow the listbox tag when clicked is able to report which variable is responsible for that particular warning. I looked at the code for nearly an hour and could not figure out how it was able to deduce that. Can you explain how the listbox is able to show the actual character involved in an unused declaration?

Also, variables declared in the main program, even if unused, are not flagged with a warning. Only local variables in methods are reported. I realize these are global variables, but the compiler should be able to deduce that no where are these variables used in the entire XojoScript.

Look at the ‘extraInfo’ argument passed in to the CompilerError/CompilerWarning events. The values in there are not guaranteed to be stable across releases, so be sure to do something like ‘extraInfo.lookup( “Name”, “” )’.