From: Francis De Brabandere <francisdb@gmail.com> When assigning with an index to a variable that is not an array or object (e.g. x(0) = 42 where x is undeclared or holds an integer), return DISP_E_TYPEMISMATCH which maps to VBS error 13 (Type mismatch), matching Windows behavior. --- dlls/vbscript/interp.c | 12 ++++------ dlls/vbscript/tests/error.vbs | 19 ++++++++++++++++ dlls/vbscript/tests/noexplicit.vbs | 36 ++++++++++++++++++++++++++++++ dlls/vbscript/tests/rsrc.rc | 3 +++ dlls/vbscript/tests/run.c | 2 ++ 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 dlls/vbscript/tests/noexplicit.vbs diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 779f3f881a5..79225af27b9 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -860,10 +860,8 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS * break; } - if(!(V_VT(v) & VT_ARRAY)) { - FIXME("array assign on type %d\n", V_VT(v)); - return E_FAIL; - } + if(!(V_VT(v) & VT_ARRAY)) + return DISP_E_TYPEMISMATCH; switch(V_VT(v)) { case VT_ARRAY|VT_BYREF|VT_VARIANT: @@ -912,10 +910,8 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS * }else { VARIANT *new_var; - if(arg_cnt(dp)) { - FIXME("arg_cnt %d not supported\n", arg_cnt(dp)); - return E_NOTIMPL; - } + if(arg_cnt(dp)) + return DISP_E_TYPEMISMATCH; TRACE("creating variable %s\n", debugstr_w(name)); hres = add_dynamic_var(ctx, name, FALSE, &new_var); diff --git a/dlls/vbscript/tests/error.vbs b/dlls/vbscript/tests/error.vbs index 40dde515f87..a115d43fb66 100644 --- a/dlls/vbscript/tests/error.vbs +++ b/dlls/vbscript/tests/error.vbs @@ -476,4 +476,23 @@ ok err.helpfile = "test.chm", "err.helpfile = " & err.helpfile on error goto 0 +' indexed assign to non-array variable should give type mismatch +dim z +z = 42 +on error resume next +z(0) = 1 +ok err.number = 13, "err.number = " & err.number +err.clear + +' Option Explicit: assigning to undeclared variable should give error 500 +undeclaredVar = 1 +todo_wine_ok err.number = 500, "err.number = " & err.number +err.clear + +' Option Explicit: reading undeclared variable should give error 500 +dim unused +unused = undeclaredVar2 +todo_wine_ok err.number = 500, "err.number = " & err.number +on error goto 0 + call reportSuccess() diff --git a/dlls/vbscript/tests/noexplicit.vbs b/dlls/vbscript/tests/noexplicit.vbs new file mode 100644 index 00000000000..f113f8c441a --- /dev/null +++ b/dlls/vbscript/tests/noexplicit.vbs @@ -0,0 +1,36 @@ +' +' Copyright 2026 Francis De Brabandere +' +' This library is free software; you can redistribute it and/or +' modify it under the terms of the GNU Lesser General Public +' License as published by the Free Software Foundation; either +' version 2.1 of the License, or (at your option) any later version. +' +' This library is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +' Lesser General Public License for more details. +' +' You should have received a copy of the GNU Lesser General Public +' License along with this library; if not, write to the Free Software +' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +' + +' Tests that require implicit variable creation (no Option Explicit) + +' assigning to undeclared variable should implicitly create it +x = 1 +ok x = 1, "x = " & x + +' reading undeclared variable should return Empty +ok getVT(y) = "VT_EMPTY*", "getVT(y) = " & getVT(y) +ok y = "", "y = " & y + +' indexed assign to undeclared variable should give type mismatch +on error resume next +z(0) = 42 +ok err.number = 13, "err.number = " & err.number +on error goto 0 + +call reportSuccess() + diff --git a/dlls/vbscript/tests/rsrc.rc b/dlls/vbscript/tests/rsrc.rc index 87d08e751d2..ccde451bf84 100644 --- a/dlls/vbscript/tests/rsrc.rc +++ b/dlls/vbscript/tests/rsrc.rc @@ -25,5 +25,8 @@ error.vbs 40 "error.vbs" /* @makedep: lang.vbs */ lang.vbs 40 "lang.vbs" +/* @makedep: noexplicit.vbs */ +noexplicit.vbs 40 "noexplicit.vbs" + /* @makedep: regexp.vbs */ regexp.vbs 40 "regexp.vbs" diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 4b69bc18ffa..9465c589aca 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3391,6 +3391,7 @@ static void run_tests(void) parse_script_w(L"x = 1\n Call ok(x = 1, \"x = \" & x)"); + parse_script_w(L"x = _ \n3"); test_global_vars_ref(TRUE); @@ -3493,6 +3494,7 @@ static void run_tests(void) run_from_res("api.vbs"); run_from_res("regexp.vbs"); run_from_res("error.vbs"); + run_from_res("noexplicit.vbs"); test_procedures(); test_gc(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10406