Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add :const for safer scripting #4541
This PR has proposed adding
Scope of variables in Vim script function is very dynamic.
let i = 0 if some_condition " In heavily nested or big statements... let i = 1 " Unexpectedly using the same name variable endif echo i " => 1
This sometimes causes a bug by modifying variables unexpectedly. To prevent this, (if
let i = 0 lockvar i if some_condition let i = 1 " Error endif echo i
const number = 42; number = 99; // TypeError: invalid assignment to const `number'
const i = 0 if some_condition let i = 1 " E995 endif echo i " => 1
let x = 0 const x = 1 " => E995
Another use case of
const s:SEP = has('win32') ? '\' : '/'
Here the constant is not intended to be modified any more. So
@brammool Thank you for your quick review and merge! My name (Ryuichi Hayashida) seems missing in the patch 8.1.1539. Would you like to keep adding it at Vim 8.2 release note at `runtime/doc/version8.txt` in your mind?
Will do. I didn't see your name on github. I'll also reference the pull request, somehow that was missing (Ken closed the pull request manually).…
-- hundred-and-one symptoms of being an internet addict: 200. You really believe in the concept of a "paperless" office. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///