Mercurial > vim
comparison runtime/doc/vim9.txt @ 27843:532a0c5de1ec v8.2.4447
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Commit: https://github.com/vim/vim/commit/afa048f0d4b5d63f2192c9ba340a9eb8b0822985
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 22 20:43:36 2022 +0000
patch 8.2.4447: Vim9: can still use s:var in a compiled function
Problem: Vim9: can still use s:var in a compiled function.
Solution: Disallow using s:var for Vim9 script. (closes https://github.com/vim/vim/issues/9824)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 22 Feb 2022 21:45:03 +0100 |
parents | 8fc68ce4a097 |
children | d19b7aee1925 |
comparison
equal
deleted
inserted
replaced
27842:4b3c59be80c7 | 27843:532a0c5de1ec |
---|---|
1 *vim9.txt* For Vim version 8.2. Last change: 2022 Feb 18 | 1 *vim9.txt* For Vim version 8.2. Last change: 2022 Feb 22 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
243 "funcref". In Vim9 script it can, therefore "s:Funcref" must be used to avoid | 243 "funcref". In Vim9 script it can, therefore "s:Funcref" must be used to avoid |
244 that the name interferes with builtin functions. | 244 that the name interferes with builtin functions. |
245 *vim9-s-namespace* | 245 *vim9-s-namespace* |
246 The use of the "s:" prefix is not supported at the Vim9 script level. All | 246 The use of the "s:" prefix is not supported at the Vim9 script level. All |
247 functions and variables without a prefix are script-local. | 247 functions and variables without a prefix are script-local. |
248 In :def functions the use of "s:" is optional. This is because in legacy | 248 |
249 script the "s:" might be needed. Disallowing the use of "s:" only in a :def | 249 In :def functions the use of "s:" depends on the script: Script-local |
250 function in Vim9 script would be a bit confusing. | 250 variables and functions in a legacy script do use "s:", while in a Vim9 script |
251 they do not use "s:". This matches what you see in the rest of the file. | |
252 | |
251 In legacy functions the use of "s:" for script items is required, as before. | 253 In legacy functions the use of "s:" for script items is required, as before. |
252 | 254 |
253 In all cases the function must be defined before used. That is when it is | 255 In all cases the function must be defined before used. That is when it is |
254 called, when `:defcompile` causes it to be compiled, or when code that calls | 256 called, when `:defcompile` causes it to be compiled, or when code that calls |
255 it is being compiled (to figure out the return type). | 257 it is being compiled (to figure out the return type). |
1465 # typename(mylist) == "list<any>" | 1467 # typename(mylist) == "list<any>" |
1466 map(mylist, (i, v) => 'item ' .. i) | 1468 map(mylist, (i, v) => 'item ' .. i) |
1467 # typename(mylist) == "list<string>", no error | 1469 # typename(mylist) == "list<string>", no error |
1468 | 1470 |
1469 There is a subtle difference between using a list constant directly and | 1471 There is a subtle difference between using a list constant directly and |
1470 through a variable declaraiton. Because of type inference, when using a list | 1472 through a variable declaration. Because of type inference, when using a list |
1471 constant to initialize a variable, this also sets the declared type: > | 1473 constant to initialize a variable, this also sets the declared type: > |
1472 var mylist = [1, 2, 3] | 1474 var mylist = [1, 2, 3] |
1473 # typename(mylist) == "list<number>" | 1475 # typename(mylist) == "list<number>" |
1474 echo map(mylist, (i, v) => 'item ' .. i) # Error! | 1476 echo map(mylist, (i, v) => 'item ' .. i) # Error! |
1475 | 1477 |