Skip to content

Commit d2e716e

Browse files
committed
patch 8.1.1188: not all Vim variables require the v: prefix
Problem: Not all Vim variables require the v: prefix. Solution: When scriptversion is 3 all Vim variables can only be used with the v: prefix. (Ken Takata, closes #4274)
1 parent 3a4c53b commit d2e716e

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

runtime/doc/eval.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,8 @@ v:count The count given for the last Normal mode command. Can be used
16881688
When there are two counts, as in "3d2w", they are multiplied,
16891689
just like what happens in the command, "d6w" for the example.
16901690
Also used for evaluating the 'formatexpr' option.
1691-
"count" also works, for backwards compatibility.
1691+
"count" also works, for backwards compatibility, unless
1692+
|scriptversion| is 3 or higher.
16921693

16931694
*v:count1* *count1-variable*
16941695
v:count1 Just like "v:count", but defaults to one when no count is
@@ -1720,7 +1721,8 @@ v:errmsg Last given error message. It's allowed to set this variable.
17201721
:silent! next
17211722
:if v:errmsg != ""
17221723
: ... handle error
1723-
< "errmsg" also works, for backwards compatibility.
1724+
< "errmsg" also works, for backwards compatibility, unless
1725+
|scriptversion| is 3 or higher.
17241726

17251727
*v:errors* *errors-variable* *assert-return*
17261728
v:errors Errors found by assert functions, such as |assert_true()|.
@@ -2023,7 +2025,8 @@ v:shell_error Result of the last shell command. When non-zero, the last
20232025
:if v:shell_error
20242026
: echo 'could not rename "foo" to "bar"!'
20252027
:endif
2026-
< "shell_error" also works, for backwards compatibility.
2028+
< "shell_error" also works, for backwards compatibility, unless
2029+
|scriptversion| is 3 or higher.
20272030

20282031
*v:statusmsg* *statusmsg-variable*
20292032
v:statusmsg Last given status message. It's allowed to set this variable.
@@ -2123,7 +2126,8 @@ v:testing Must be set before using `test_garbagecollect_now()`.
21232126
v:this_session Full filename of the last loaded or saved session file. See
21242127
|:mksession|. It is allowed to set this variable. When no
21252128
session file has been saved, this variable is empty.
2126-
"this_session" also works, for backwards compatibility.
2129+
"this_session" also works, for backwards compatibility, unless
2130+
|scriptversion| is 3 or higher
21272131

21282132
*v:throwpoint* *throwpoint-variable*
21292133
v:throwpoint The point where the exception most recently caught and not
@@ -2154,7 +2158,7 @@ v:val Value of the current item of a |List| or |Dictionary|. Only
21542158
v:version Version number of Vim: Major version number times 100 plus
21552159
minor version number. Version 5.0 is 500. Version 5.1 (5.01)
21562160
is 501. Read-only. "version" also works, for backwards
2157-
compatibility.
2161+
compatibility, unless |scriptversion| is 3 or higher.
21582162
Use |has()| to check if a certain patch was included, e.g.: >
21592163
if has("patch-7.4.123")
21602164
< Note that patch numbers are specific to the version, thus both

src/eval.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7672,10 +7672,14 @@ find_var_ht(char_u *name, char_u **varname)
76727672
return NULL;
76737673
*varname = name;
76747674

7675-
/* "version" is "v:version" in all scopes */
7676-
hi = hash_find(&compat_hashtab, name);
7677-
if (!HASHITEM_EMPTY(hi))
7678-
return &compat_hashtab;
7675+
// "version" is "v:version" in all scopes if scriptversion < 3.
7676+
// Same for a few other variables marked with VV_COMPAT.
7677+
if (current_sctx.sc_version < 3)
7678+
{
7679+
hi = hash_find(&compat_hashtab, name);
7680+
if (!HASHITEM_EMPTY(hi))
7681+
return &compat_hashtab;
7682+
}
76797683

76807684
ht = get_funccal_local_ht();
76817685
if (ht == NULL)

src/ex_cmds2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5127,7 +5127,7 @@ ex_scriptversion(exarg_T *eap UNUSED)
51275127
nr = getdigits(&eap->arg);
51285128
if (nr == 0 || *eap->arg != NUL)
51295129
emsg(_(e_invarg));
5130-
else if (nr > 2)
5130+
else if (nr > 3)
51315131
semsg(_("E999: scriptversion not supported: %d"), nr);
51325132
else
51335133
current_sctx.sc_version = nr;

src/testdir/test_eval_stuff.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ func Test_string_concat_scriptversion1()
154154
endif
155155
endfunc
156156

157+
scriptversion 3
158+
func Test_vvar_scriptversion3()
159+
call assert_fails('echo version', 'E121:')
160+
call assert_false(exists('version'))
161+
let version = 1
162+
call assert_equal(1, version)
163+
endfunc
164+
165+
scriptversion 2
166+
func Test_vvar_scriptversion2()
167+
call assert_true(exists('version'))
168+
echo version
169+
call assert_fails('let version = 1', 'E46:')
170+
call assert_equal(v:version, version)
171+
endfunc
172+
157173
func Test_scriptversion()
158174
call writefile(['scriptversion 9'], 'Xversionscript')
159175
call assert_fails('source Xversionscript', 'E999:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1188,
774776
/**/
775777
1187,
776778
/**/

0 commit comments

Comments
 (0)