From: Francis De Brabandere <francisdb@gmail.com> When Option Explicit is set and a For loop uses an undefined variable, throw error 500 (Variable is undefined) with proper description instead of just returning E_FAIL. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57511 --- dlls/vbscript/interp.c | 3 +-- dlls/vbscript/tests/error.vbs | 15 +++++++++++++++ dlls/vbscript/vbscript.rc | 1 + dlls/vbscript/vbscript_defs.h | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 127fcc2c05e..5a28c1e0386 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -906,8 +906,7 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS * return E_NOTIMPL; 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; diff --git a/dlls/vbscript/tests/error.vbs b/dlls/vbscript/tests/error.vbs index 9b74dc8773e..ee86e0e06b1 100644 --- a/dlls/vbscript/tests/error.vbs +++ b/dlls/vbscript/tests/error.vbs @@ -476,4 +476,19 @@ ok err.helpfile = "test.chm", "err.helpfile = " & err.helpfile on error goto 0 +' Test undefined variable in For loop (with Option Explicit) +on error resume next +dim testArr +testArr = Array(1,2,3) +' undefinedVar is not declared - should cause error 500 +For undefinedVar = 0 To UBound(testArr) + trace "should not reach here" +Next +ok Err.Number = 500, "Err.Number = " & Err.Number & " (expected 500)" +ok Err.Description <> "", "Err.Description should not be empty, got: " & Err.Description +ok Err.HelpContext = 0, "Err.HelpContext = " & Err.HelpContext & " (expected 0)" +ok Err.HelpFile = "", "Err.HelpFile should be empty, got: " & Err.HelpFile +Err.Clear +on error goto 0 + call reportSuccess() diff --git a/dlls/vbscript/vbscript.rc b/dlls/vbscript/vbscript.rc index cf157f77526..50e7cf12f93 100644 --- a/dlls/vbscript/vbscript.rc +++ b/dlls/vbscript/vbscript.rc @@ -56,6 +56,7 @@ STRINGTABLE VBSE_INVALID_DLL_FUNCTION_NAME "Specified DLL function not found" VBSE_INVALID_TYPELIB_VARIABLE "Variable uses an Automation type not supported in VBScript" VBSE_SERVER_NOT_FOUND "The remote server machine does not exist or is unavailable" + VBSE_VARIABLE_UNDEFINED "Variable is undefined" VBSE_UNQUALIFIED_REFERENCE "Invalid or unqualified reference" VBS_COMPILE_ERROR "Microsoft VBScript compilation error" diff --git a/dlls/vbscript/vbscript_defs.h b/dlls/vbscript/vbscript_defs.h index 139b71255a0..92bd236ad6b 100644 --- a/dlls/vbscript/vbscript_defs.h +++ b/dlls/vbscript/vbscript_defs.h @@ -267,6 +267,7 @@ #define VBSE_INVALID_DLL_FUNCTION_NAME 453 #define VBSE_INVALID_TYPELIB_VARIABLE 458 #define VBSE_SERVER_NOT_FOUND 462 +#define VBSE_VARIABLE_UNDEFINED 500 #define VBSE_UNQUALIFIED_REFERENCE 505 #define VBS_COMPILE_ERROR 4096 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10374