From: Francis De Brabandere <francisdb@gmail.com> A global control-flow conditional (If/ElseIf/Else/Select) hoists a Sub or Function to global scope, but a loop (For/For Each/While/Do) or With block does not - a declaration there is an error, wherever it appears within the loop. Reject it during parsing, matching native. --- dlls/vbscript/parser.y | 8 ++++---- dlls/vbscript/tests/run.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index ba76a1076a0..3d3897c7510 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -1175,7 +1175,7 @@ static statement_t *new_while_statement(parser_ctx_t *ctx, unsigned loc, stateme { while_statement_t *stat; - if(reject_nested_class(ctx, body)) + if(reject_nested_decl(ctx, body)) return NULL; stat = new_statement(ctx, type, sizeof(*stat), loc); @@ -1192,7 +1192,7 @@ static statement_t *new_forto_statement(parser_ctx_t *ctx, unsigned loc, const W { forto_statement_t *stat; - if(reject_nested_class(ctx, body)) + if(reject_nested_decl(ctx, body)) return NULL; stat = new_statement(ctx, STAT_FORTO, sizeof(*stat), loc); @@ -1212,7 +1212,7 @@ static statement_t *new_foreach_statement(parser_ctx_t *ctx, unsigned loc, const { foreach_statement_t *stat; - if(reject_nested_class(ctx, body)) + if(reject_nested_decl(ctx, body)) return NULL; stat = new_statement(ctx, STAT_FOREACH, sizeof(*stat), loc); @@ -1261,7 +1261,7 @@ static statement_t *new_with_statement(parser_ctx_t *ctx, unsigned loc, expressi { with_statement_t *stat; - if(reject_nested_class(ctx, body)) + if(reject_nested_decl(ctx, body)) return NULL; stat = new_statement(ctx, STAT_WITH, sizeof(*stat), loc); diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index fda7e391f2e..f8e04dc4655 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3500,6 +3500,18 @@ static void test_parse_errors(void) L"If True Then\nClass C\nEnd Class\nEnd If\n", 1, 0, NULL, S_OK, 1002 + }, + { + /* Sub inside a global loop is not hoisted - error 1002 */ + L"For i = 1 To 1\nSub S\nEnd Sub\nNext\n", + 1, 0, + NULL, S_OK, 1002 + }, + { + /* ... even when nested in a conditional inside the loop - error 1002 */ + L"For i = 1 To 1\nIf True Then\nSub S\nEnd Sub\nEnd If\nNext\n", + 2, 0, + NULL, S_OK, 1002 } }; HRESULT hres; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10897