diff options
-rw-r--r-- | src/errors.h | 2 | ||||
-rw-r--r-- | src/evalfunc.c | 25 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 16 | ||||
-rw-r--r-- | src/typval.c | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
5 files changed, 46 insertions, 3 deletions
diff --git a/src/errors.h b/src/errors.h index aaf7e552c9..39eca7e943 100644 --- a/src/errors.h +++ b/src/errors.h @@ -359,3 +359,5 @@ EXTERN char e_cannot_use_default_for_variable_arguments[] INIT(= N_("E1160: Cannot use a default for variable arguments")); EXTERN char e_cannot_json_encode_str[] INIT(= N_("E1161: Cannot json encode a %s")); +EXTERN char e_register_name_must_be_one_char_str[] + INIT(= N_("E1162: Register name must be one character: %s")); diff --git a/src/evalfunc.c b/src/evalfunc.c index 01994b0475..b3da9f6cf6 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4285,7 +4285,13 @@ f_getreg(typval_T *argvars, typval_T *rettv) if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); - error = strregname == NULL; + if (strregname == NULL) + error = TRUE; + else if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + error = TRUE; + } if (argvars[1].v_type != VAR_UNKNOWN) { arg2 = (int)tv_get_bool_chk(&argvars[1], &error); @@ -4335,6 +4341,11 @@ f_getregtype(typval_T *argvars, typval_T *rettv) if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); + if (strregname != NULL && in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + strregname = NULL; + } if (strregname == NULL) // type error; errmsg already given { rettv->v_type = VAR_STRING; @@ -7368,6 +7379,11 @@ f_getreginfo(typval_T *argvars, typval_T *rettv) strregname = tv_get_string_chk(&argvars[0]); if (strregname == NULL) return; + if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + return; + } } else strregname = get_vim_var_str(VV_REG); @@ -7410,7 +7426,7 @@ f_getreginfo(typval_T *argvars, typval_T *rettv) { item->di_tv.v_type = VAR_SPECIAL; item->di_tv.vval.v_number = regname == buf[0] - ? VVAL_TRUE : VVAL_FALSE; + ? VVAL_TRUE : VVAL_FALSE; (void)dict_add(dict, item); } } @@ -8472,6 +8488,11 @@ f_setreg(typval_T *argvars, typval_T *rettv) if (strregname == NULL) return; // type error; errmsg already given + if (in_vim9script() && STRLEN(strregname) > 1) + { + semsg(_(e_register_name_must_be_one_char_str), strregname); + return; + } regname = *strregname; if (regname == 0 || regname == '@') regname = '"'; diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index eb36bd77a1..cb36990657 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -531,6 +531,7 @@ def Test_getreg() var lines = ['aaa', 'bbb', 'ccc'] setreg('a', lines) getreg('a', true, true)->assert_equal(lines) + assert_fails('getreg("ab")', 'E1162:') enddef def Test_getreg_return_type() @@ -539,6 +540,20 @@ def Test_getreg_return_type() var s3: list<string> = getreg('"', 1, 1) enddef +def Test_getreginfo() + var text = 'abc' + setreg('a', text) + getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false}) + assert_fails('getreginfo("ab")', 'E1162:') +enddef + +def Test_getregtype() + var lines = ['aaa', 'bbb', 'ccc'] + setreg('a', lines) + getregtype('a')->assert_equal('V') + assert_fails('getregtype("ab")', 'E1162:') +enddef + def Test_glob() glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) enddef @@ -878,6 +893,7 @@ def Test_setreg() var reginfo = getreginfo('a') setreg('a', reginfo) getreginfo('a')->assert_equal(reginfo) + assert_fails('setreg("ab", 0)', 'E1162:') enddef def Test_slice() diff --git a/src/typval.c b/src/typval.c index 65e07b3f79..1cdab93ef1 100644 --- a/src/typval.c +++ b/src/typval.c @@ -1069,7 +1069,9 @@ tv_equal( return r; } - if (tv1->v_type != tv2->v_type) + if (tv1->v_type != tv2->v_type + && ((tv1->v_type != VAR_BOOL && tv1->v_type != VAR_SPECIAL) + || (tv2->v_type != VAR_BOOL && tv2->v_type != VAR_SPECIAL))) return FALSE; switch (tv1->v_type) diff --git a/src/version.c b/src/version.c index 3c9edfdce9..55dd8d164e 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2497, +/**/ 2496, /**/ 2495, |