diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-06 15:36:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 15:36:15 +0800 |
commit | c6af296cf8e381731f8a233cf89396e0dc7fd4ba (patch) | |
tree | 790ab58f00b2c00656639d8228edf35aff1d850c | |
parent | 850d7146fc7fb57691641c729d5580b834cd7dd2 (diff) | |
parent | ed01ef7fa5c2611748f90acfdc2145b22629dc36 (diff) | |
download | rneovim-c6af296cf8e381731f8a233cf89396e0dc7fd4ba.tar.gz rneovim-c6af296cf8e381731f8a233cf89396e0dc7fd4ba.tar.bz2 rneovim-c6af296cf8e381731f8a233cf89396e0dc7fd4ba.zip |
Merge pull request #20961 from zeertzjq/vim-8.2.3055
vim-patch:8.2.3055,9.0.0355
-rw-r--r-- | src/nvim/eval.c | 19 | ||||
-rw-r--r-- | src/nvim/eval/vars.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_let.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_listdict.vim | 3 |
4 files changed, 28 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 72df343932..fe4ae92834 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -66,6 +66,8 @@ static char *e_nowhitespace static char *e_write2 = N_("E80: Error while writing: %s"); static char *e_string_list_or_blob_required = N_("E1098: String, List or Blob required"); static char e_expression_too_recursive_str[] = N_("E1169: Expression too recursive: %s"); +static char e_dot_can_only_be_used_on_dictionary_str[] + = N_("E1203: Dot can only be used on a dictionary: %s"); static char * const namespace_char = "abglstvw"; @@ -1313,13 +1315,26 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const return NULL; } - // Loop until no more [idx] or .key is following. lp->ll_tv = &v->di_tv; + + if (tv_is_luafunc(lp->ll_tv)) { + // For v:lua just return a pointer to the "." after the "v:lua". + // If the caller is trans_function_name() it will check for a Lua function name. + return p; + } + + // Loop until no more [idx] or .key is following. typval_T var1; var1.v_type = VAR_UNKNOWN; typval_T var2; var2.v_type = VAR_UNKNOWN; - while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) { + while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.')) { + if (*p == '.' && lp->ll_tv->v_type != VAR_DICT) { + if (!quiet) { + semsg(_(e_dot_can_only_be_used_on_dictionary_str), name); + } + return NULL; + } if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) && !(lp->ll_tv->v_type == VAR_DICT && lp->ll_tv->vval.v_dict != NULL) && !(lp->ll_tv->v_type == VAR_BLOB && lp->ll_tv->vval.v_blob != NULL)) { diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index a0877deaf7..139e7ed66b 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -1453,9 +1453,10 @@ bool var_wrong_func_name(const char *const name, const bool new_var) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { // Allow for w: b: s: and t:. + // Allow autoload variable. if (!(vim_strchr("wbst", name[0]) != NULL && name[1] == ':') - && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') - ? name[2] : name[0])) { + && !ASCII_ISUPPER((name[0] != NUL && name[1] == ':') ? name[2] : name[0]) + && vim_strchr(name, '#') == NULL) { semsg(_("E704: Funcref variable name must start with a capital: %s"), name); return true; } diff --git a/src/nvim/testdir/test_let.vim b/src/nvim/testdir/test_let.vim index cb883fc238..35745e9c6a 100644 --- a/src/nvim/testdir/test_let.vim +++ b/src/nvim/testdir/test_let.vim @@ -6,6 +6,10 @@ func Test_let() let Test104#numvar = function('tr') call assert_equal("function('tr')", string(Test104#numvar)) + let foo#tr = function('tr') + call assert_equal("function('tr')", string(foo#tr)) + unlet foo#tr + let a = 1 let b = 2 @@ -276,7 +280,7 @@ func Test_let_errors() let s = "var" let var = 1 call assert_fails('let var += [1,2]', 'E734:') - call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let {s}.1 = 2', 'E1203:') call assert_fails('let a[1] = 5', 'E121:') let l = [[1,2]] call assert_fails('let l[:][0] = [5]', 'E708:') diff --git a/src/nvim/testdir/test_listdict.vim b/src/nvim/testdir/test_listdict.vim index 21d21ce428..3d90222b90 100644 --- a/src/nvim/testdir/test_listdict.vim +++ b/src/nvim/testdir/test_listdict.vim @@ -294,6 +294,9 @@ func Test_dict_assign() let d.1 = 1 let d._ = 2 call assert_equal({'1': 1, '_': 2}, d) + + let n = 0 + call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3') endfunc " Function in script-local List or Dict |