Mercurial > vim
changeset 21674:f303d6a01a3e v8.2.1387
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Commit: https://github.com/vim/vim/commit/95dd9f2571f09a915674133c73b471b0ebbdcdbf
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 7 19:28:08 2020 +0200
patch 8.2.1387: Vim9: cannot assign to single letter variable with type
Problem: Vim9: cannot assign to single letter variable with type.
Solution: Exclude the colon from the variable name. (closes https://github.com/vim/vim/issues/6647)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 07 Aug 2020 19:30:06 +0200 |
parents | 1731db1dc52c |
children | 49ed426f3fb5 |
files | src/eval.c src/testdir/test_vim9_script.vim src/version.c |
diffstat | 3 files changed, 29 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -820,14 +820,23 @@ get_lval( { lp->ll_name = name; - if (in_vim9script() && *p == ':') + if (in_vim9script()) { - scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); - char_u *tp = skipwhite(p + 1); - - // parse the type after the name - lp->ll_type = parse_type(&tp, &si->sn_type_list); - lp->ll_name_end = tp; + // "a: type" is declaring variable "a" with a type, not "a:". + if (p == name + 2 && p[-1] == ':') + { + --p; + lp->ll_name_end = p; + } + if (*p == ':') + { + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); + char_u *tp = skipwhite(p + 1); + + // parse the type after the name + lp->ll_type = parse_type(&tp, &si->sn_type_list); + lp->ll_name_end = tp; + } } }
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -449,6 +449,17 @@ def Test_assignment_vim9script() @+ = 'plus' assert_equal('plus', @+) endif + + let a: number = 123 + assert_equal(123, a) + let s: string = 'yes' + assert_equal('yes', s) + let b: number = 42 + assert_equal(42, b) + let w: number = 43 + assert_equal(43, w) + let t: number = 44 + assert_equal(44, t) END CheckScriptSuccess(lines) enddef