From: Francis De Brabandere <francisdb@gmail.com> Execute pre-registers Dim variables in the caller's dynamic_vars when invoked from a Sub or Function, but interp_dim's FUNC_GLOBAL path only looked them up in the script object, hitting an assertion when the OP_dim instruction ran for a fixed-size array. --- dlls/vbscript/interp.c | 8 ++++++++ dlls/vbscript/tests/lang.vbs | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 219b4fdefda..5940d5b98f9 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1400,6 +1400,14 @@ static HRESULT interp_dim(exec_ctx_t *ctx) if(ctx->func->type == FUNC_GLOBAL) { dynamic_var_t *var = script_disp_find_var(script_obj, ident); + if(!var && ctx->caller) { + /* Execute() called from a local scope pre-registers Dim + * variables in the caller's dynamic_vars, not the script object. */ + for(var = ctx->caller->dynamic_vars; var; var = var->next) { + if(!vbs_wcsicmp(var->name, ident)) + break; + } + } assert(var != NULL); v = &var->v; array_ref = &var->array; diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 1b6cdf763e4..d25b4e3b248 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -4055,6 +4055,15 @@ Sub TestExecuteReDim End Sub Call TestExecuteReDim +' Execute: fixed-size Dim array in caller's scope +Sub TestExecuteFixedDim + Execute "Dim fixedArr(2) : fixedArr(0) = 1 : fixedArr(1) = 2 : fixedArr(2) = 3" + Call ok(fixedArr(0) = 1, "Execute Dim fixedArr(0) = " & fixedArr(0)) + Call ok(fixedArr(2) = 3, "Execute Dim fixedArr(2) = " & fixedArr(2)) + Call ok(UBound(fixedArr) = 2, "Execute Dim UBound(fixedArr) = " & UBound(fixedArr)) +End Sub +Call TestExecuteFixedDim + ' Option Explicit is per-compilation-unit in Execute/ExecuteGlobal On Error Resume Next -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10896