From: Francis De Brabandere <francisdb@gmail.com> When Option Explicit is set and a For loop uses an undefined variable, return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED) (error 500) instead of E_FAIL. Fix both interp_step and interp_incc to handle REF_NONE by returning the proper VBS error code with description. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57511 --- dlls/vbscript/interp.c | 7 +++++-- dlls/vbscript/tests/error.vbs | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 4bbdad181e0..fe94592d0e6 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -957,8 +957,7 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS * return MAKE_VBSERROR(VBSE_ILLEGAL_ASSIGNMENT); case REF_NONE: if(ctx->func->code_ctx->option_explicit) { - FIXME("throw exception\n"); - hres = E_FAIL; + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); }else { VARIANT *new_var; @@ -1578,6 +1577,8 @@ static HRESULT interp_step(exec_ctx_t *ctx) return hres; if(ref.type != REF_VAR) { + if(ref.type == REF_NONE) + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); FIXME("%s is not REF_VAR\n", debugstr_w(ident)); return E_FAIL; } @@ -2510,6 +2511,8 @@ static HRESULT interp_incc(exec_ctx_t *ctx) return hres; if(ref.type != REF_VAR) { + if(ref.type == REF_NONE) + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); FIXME("ref.type is not REF_VAR\n"); return E_FAIL; } diff --git a/dlls/vbscript/tests/error.vbs b/dlls/vbscript/tests/error.vbs index fa9ca6b7902..3871580c492 100644 --- a/dlls/vbscript/tests/error.vbs +++ b/dlls/vbscript/tests/error.vbs @@ -235,6 +235,15 @@ sub testThrow call ok(x = 6, "x = " & x) call ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number) + Err.clear() + y = 0 + for undefinedVar = 0 To 3 + y = y + 1 + next + call ok(y = 1, "y = " & y) + call ok(Err.Number = 500, "Err.Number = " & Err.Number) + call ok(Err.Description <> "", "Err.Description should not be empty, got: " & Err.Description) + select case throwInt(E_TESTERROR) case true call ok(false, "unexpected case true") -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10374