https://bugs.winehq.org/show_bug.cgi?id=54177
Bug ID: 54177 Summary: vbscript fails to compile sub call when argument expression contains multiplication Product: Wine Version: 7.21 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: vbscript Assignee: wine-bugs@winehq.org Reporter: jsm174@gmail.com Distribution: ---
While working on the port of Visual Pinball, we found a script with code similar to the following that fails to compile:
Public Sub AddTimer(aDelay, aMessage) End Sub
Dim ii ii = 1
AddTimer (ii-1)*200, "Message"
If the expression is wrapped in parenthesis, it compiles successfully:
AddTimer ((ii-1)*200), "Message"
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #1 from Jason Millard jsm174@gmail.com --- After looking at the grammar:
FunctionDecl : Storage_opt tSUB Identifier ArgumentsDecl_opt StSep BodyStatements tEND tSUB { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
ArgumentsDecl_opt : EmptyBrackets_opt { $$ = NULL; } | '(' ArgumentDeclList ')' { $$ = $2; }
ArgumentDeclList : ArgumentDecl { $$ = $1; } | ArgumentDecl ',' ArgumentDeclList { $1->next = $3; $$ = $1; }
I'm guessing (ii-1) runs through (' ArgumentDeclList ')'
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #2 from Jason Millard jsm174@gmail.com --- (In reply to Jason Millard from comment #1)
I'm guessing (ii-1) runs through (' ArgumentDeclList ')'
Actually that was for the Sub declaration.
Maybe it's a call expression:
Arguments : tEMPTYBRACKETS { $$ = NULL; } | '(' ArgumentList ')' { $$ = $2; }
https://bugs.winehq.org/show_bug.cgi?id=54177
francisdb francisdb@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |francisdb@gmail.com
--- Comment #3 from francisdb francisdb@gmail.com --- I can confirm this issue
DMDScene.GetImage("Dig" & i).SetBounds (i - 20) * 16, 10, 16, 16
requires this workaround
DMDScene.GetImage("Dig" & i).SetBounds ((i - 20) * 16), 10, 16, 16
https://bugs.winehq.org/show_bug.cgi?id=54177
Damjan Jovanovic damjan.jov@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 CC| |damjan.jov@gmail.com Status|UNCONFIRMED |NEW
--- Comment #4 from Damjan Jovanovic damjan.jov@gmail.com --- (In reply to Jason Millard from comment #2)
(In reply to Jason Millard from comment #1)
I'm guessing (ii-1) runs through (' ArgumentDeclList ')'
Actually that was for the Sub declaration.
Maybe it's a call expression:
Arguments : tEMPTYBRACKETS { $$ = NULL; } | '(' ArgumentList ')' { $$ = $2; }
Yes I think this is the problem.
Changing the '*' to '+' or '-' ends up in a "missing comma" error. It seems to be parsing it like this:
Arguments Error | | | | | |+--------+ | | || | v vv v AddTimer (ii-1)*200, "Message"
which will break regardless of what follows the ')'.
The brackets should be treated as part of the first argument, not as the argument list boundaries.
Easy to reproduce with: wine cscript 'z:\path\to\file.vbs'
Confirming.
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #5 from francisdb francisdb@gmail.com --- Found another case.
On windows this works:
MatchReel1.SetValue(Match \ 10) + 1
On wine vbscript this needs to be patched to
MatchReel1.SetValue ((Match \ 10) + 1)
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #6 from francisdb francisdb@gmail.com --- This issue is extra annoying as the error is reported on line 0.
To find the line causing this I fall back to bisecting until I found the offending lines.
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #7 from Jason Millard jsm174@gmail.com --- (In reply to francisdb from comment #6)
This issue is extra annoying as the error is reported on line 0.
To find the line causing this I fall back to bisecting until I found the offending lines.
Hello. This is related to Visual Pinball standalone which is using Wine's vbs engine.
@francisdb, this is only reported as line 0 because of how the function is being called in vpx. Our version is forked to support eval, execute, and execute global. Wine's vbscript engine does not yet have these implemented.
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #8 from francisdb francisdb@gmail.com --- Aha, sorry about that. Should have tested with pure wine.
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #9 from francisdb francisdb@gmail.com --- Found another case
DisplayB2SText (score(currentplayer)) &" " & " BALL 1 "
Needs to be changed to
DisplayB2SText ((score(currentplayer)) &" " & " BALL 1 ")
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #10 from francisdb francisdb@gmail.com --- The actual issue is the bracket that is part of the first argument and directly after the sub.
X.SetBounds (i - 20) * 8, 3, 8, 16
workaround
X.SetBounds 8 * (i - 20), 3, 8, 16
https://bugs.winehq.org/show_bug.cgi?id=54177
--- Comment #11 from francisdb francisdb@gmail.com --- The commit that broke this is:
https://gitlab.winehq.org/wine/wine/-/commit/509044296dde3688cfdaaf02325a1bc...
The provided solution of detecting a call in the lexer is incorrect as there might be an expression that starts with a bracket.
Test code to add in lang.vbs:
Sub TestWithBracketsAtStartFirstArg(a) Call ok(a=2, "a = " & a & " (expected 2)") End Sub TestWithBracketsAtStartFirstArg (1) + 1