To: vim_dev@googlegroups.com Subject: Patch 8.2.1469 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1469 Problem: Vim9: cannot assign string to string option. Solution: Change checks for option value. (closes #6720) Files: src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1468/src/evalvars.c 2020-08-15 16:33:24.501747305 +0200 --- src/evalvars.c 2020-08-16 20:33:20.669450157 +0200 *************** *** 1294,1321 **** emsg(_(e_letunexp)); else { ! long n; int opt_type; long numval; char_u *stringval = NULL; char_u *s = NULL; c1 = *p; *p = NUL; ! n = (long)tv_get_number(tv); ! // avoid setting a string option to the text "v:false" or similar. ! if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) ! s = tv_get_string_chk(tv); // != NULL if number or string ! if (s != NULL && op != NULL && *op != '=') { - opt_type = get_option_value(arg, &numval, - &stringval, opt_flags); if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { semsg(_(e_letwrong), op); ! s = NULL; // don't set the value } else { --- 1294,1329 ---- emsg(_(e_letunexp)); else { ! long n = 0; int opt_type; long numval; char_u *stringval = NULL; char_u *s = NULL; + int failed = FALSE; c1 = *p; *p = NUL; ! opt_type = get_option_value(arg, &numval, &stringval, opt_flags); ! if ((opt_type == 1 || opt_type == -1) ! && (tv->v_type != VAR_STRING || !in_vim9script())) ! // number, possibly hidden ! n = (long)tv_get_number(tv); ! ! // Avoid setting a string option to the text "v:false" or similar. ! // In Vim9 script also don't convert a number to string. ! if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL ! && (!in_vim9script() || tv->v_type != VAR_NUMBER)) ! s = tv_get_string_chk(tv); ! ! if (op != NULL && *op != '=') { if ((opt_type == 1 && *op == '.') || (opt_type == 0 && *op != '.')) { semsg(_(e_letwrong), op); ! failed = TRUE; // don't set the value ! } else { *************** *** 1330,1348 **** case '%': n = (long)num_modulus(numval, n); break; } } ! else if (opt_type == 0 && stringval != NULL) // string { s = concat_str(stringval, s); vim_free(stringval); stringval = s; } } } ! if (s != NULL || tv->v_type == VAR_BOOL ! || tv->v_type == VAR_SPECIAL) { ! set_option_value(arg, n, s, opt_flags); ! arg_end = p; } *p = c1; vim_free(stringval); --- 1338,1362 ---- case '%': n = (long)num_modulus(numval, n); break; } } ! else if (opt_type == 0 && stringval != NULL && s != NULL) { + // string s = concat_str(stringval, s); vim_free(stringval); stringval = s; } } } ! ! if (!failed) { ! if (opt_type != 0 || s != NULL) ! { ! set_option_value(arg, n, s, opt_flags); ! arg_end = p; ! } ! else ! emsg(_(e_stringreq)); } *p = c1; vim_free(stringval); *** ../vim-8.2.1468/src/testdir/test_vim9_script.vim 2020-08-16 18:29:31.480642573 +0200 --- src/testdir/test_vim9_script.vim 2020-08-16 20:11:12.595684126 +0200 *************** *** 96,117 **** &ts += 3 assert_equal(9, &ts) END ! call CheckScriptSuccess(lines) ! call CheckDefFailure(['¬ex += 3'], 'E113:') ! call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:') ! call CheckDefFailure(['&ts = [7]'], 'E1012:') ! call CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list') ! call CheckDefFailure(['&ts = "xx"'], 'E1012:') ! call CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string') ! call CheckDefFailure(['&path += 3'], 'E1012:') ! call CheckDefExecFailure(['&bs = "asdf"'], 'E474:') # test freeing ISN_STOREOPT ! call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:') &ts = 8 ! call CheckDefFailure(['let s:var = 123'], 'E1101:') ! call CheckDefFailure(['let s:var: number'], 'E1101:') lines =<< trim END vim9script --- 96,131 ---- &ts += 3 assert_equal(9, &ts) END ! CheckScriptSuccess(lines) ! CheckDefFailure(['¬ex += 3'], 'E113:') ! CheckDefFailure(['&ts ..= "xxx"'], 'E1019:') ! CheckDefFailure(['&ts = [7]'], 'E1012:') ! CheckDefExecFailure(['&ts = g:alist'], 'E1029: Expected number but got list') ! CheckDefFailure(['&ts = "xx"'], 'E1012:') ! CheckDefExecFailure(['&ts = g:astring'], 'E1029: Expected number but got string') ! CheckDefFailure(['&path += 3'], 'E1012:') ! CheckDefExecFailure(['&bs = "asdf"'], 'E474:') # test freeing ISN_STOREOPT ! CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:') &ts = 8 ! lines =<< trim END ! let save_TI = &t_TI ! &t_TI = '' ! assert_equal('', &t_TI) ! &t_TI = 'xxx' ! assert_equal('xxx', &t_TI) ! &t_TI = save_TI ! END ! CheckDefSuccess(lines) ! CheckScriptSuccess(['vim9script'] + lines) ! ! CheckDefFailure(['&t_TI = 123'], 'E1012:') ! CheckScriptFailure(['vim9script', '&t_TI = 123'], 'E928:') ! ! CheckDefFailure(['let s:var = 123'], 'E1101:') ! CheckDefFailure(['let s:var: number'], 'E1101:') lines =<< trim END vim9script *** ../vim-8.2.1468/src/version.c 2020-08-16 18:42:50.678811797 +0200 --- src/version.c 2020-08-16 21:28:51.990707434 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1469, /**/ -- hundred-and-one symptoms of being an internet addict: 218. Your spouse hands you a gift wrapped magnet with your PC's name on it and you accuse him or her of genocide. /// 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 ///