Skip to content

Commit

Permalink
Make "v:" prefix mandatory in scriptversion 2
Browse files Browse the repository at this point in the history
"version" cannot be used as "v:version" in scriptversion 2 anymore.
It can be used as a normal variable.
  • Loading branch information
k-takata committed Apr 17, 2019
1 parent 1a4dce7 commit f76584a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12713,6 +12713,10 @@ instead of failing in mysterious ways. >
< String concatenation with "." is not supported, use ".." instead.
This avoids the ambiguity using "." for Dict member access and
floating point numbers. Now ".5" means the number 0.5.

All |vim-variable|s must be prefixed by "v:". E.g. "version" doesn't
work as |v:version| anymore. It can be used as a normal variable.

Test for support with: >
has('vimscript-2')
Expand Down
11 changes: 7 additions & 4 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7672,10 +7672,13 @@ find_var_ht(char_u *name, char_u **varname)
return NULL;
*varname = name;

/* "version" is "v:version" in all scopes */
hi = hash_find(&compat_hashtab, name);
if (!HASHITEM_EMPTY(hi))
return &compat_hashtab;
// "version" is "v:version" in all scopes if scriptversion is 1.
if (current_sctx.sc_version < 2)
{
hi = hash_find(&compat_hashtab, name);
if (!HASHITEM_EMPTY(hi))
return &compat_hashtab;
}

ht = get_funccal_local_ht();
if (ht == NULL)
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/test_eval_stuff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func Test_string_concat_scriptversion2()
call assert_fails('let a .= b', 'E985:')
call assert_fails('let vers = 1.2.3', 'E15:')

call assert_fails('echo version', 'E121:')
let version = 1
call assert_equal(1, version)

if has('float')
let f = .5
call assert_equal(0.5, f)
Expand All @@ -149,6 +153,10 @@ func Test_string_concat_scriptversion1()
let vers = 1.2.3
call assert_equal('123', vers)

echo version
call assert_fails('let version = 1', 'E46:')
call assert_equal(v:version, version)

if has('float')
call assert_fails('let f = .5', 'E15:')
endif
Expand Down

0 comments on commit f76584a

Please sign in to comment.