To: vim_dev@googlegroups.com Subject: Patch 8.2.1489 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1489 Problem: Vim9: error when setting an option with setbufvar(). Solution: Do not get a number from a string value. (closes #6740) Files: src/evalvars.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1488/src/evalvars.c 2020-08-17 21:07:17.941045702 +0200 --- src/evalvars.c 2020-08-19 21:16:59.454079678 +0200 *************** *** 3293,3298 **** --- 3293,3316 ---- } /* + * Set option "varname" to the value of "varp" for the current buffer/window. + */ + static void + set_option_from_tv(char_u *varname, typval_T *varp) + { + long numval = 0; + char_u *strval; + char_u nbuf[NUMBUFLEN]; + int error = FALSE; + + if (!in_vim9script() || varp->v_type != VAR_STRING) + numval = (long)tv_get_number_chk(varp, &error); + strval = tv_get_string_buf_chk(varp, nbuf); + if (!error && strval != NULL) + set_option_value(varname, numval, strval, OPT_LOCAL); + } + + /* * "setwinvar()" and "settabwinvar()" functions */ static void *************** *** 3304,3310 **** int need_switch_win; char_u *varname, *winvarname; typval_T *varp; - char_u nbuf[NUMBUFLEN]; tabpage_T *tp = NULL; if (check_secure()) --- 3322,3327 ---- *************** *** 3325,3341 **** || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) { if (*varname == '&') ! { ! long numval; ! char_u *strval; ! int error = FALSE; ! ! ++varname; ! numval = (long)tv_get_number_chk(varp, &error); ! strval = tv_get_string_buf_chk(varp, nbuf); ! if (!error && strval != NULL) ! set_option_value(varname, numval, strval, OPT_LOCAL); ! } else { winvarname = alloc(STRLEN(varname) + 3); --- 3342,3348 ---- || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) { if (*varname == '&') ! set_option_from_tv(varname + 1, varp); else { winvarname = alloc(STRLEN(varname) + 3); *************** *** 3759,3765 **** buf_T *buf; char_u *varname, *bufvarname; typval_T *varp; - char_u nbuf[NUMBUFLEN]; if (check_secure()) return; --- 3766,3771 ---- *************** *** 3772,3790 **** { if (*varname == '&') { - long numval; - char_u *strval; - int error = FALSE; aco_save_T aco; // set curbuf to be our buf, temporarily aucmd_prepbuf(&aco, buf); ! ++varname; ! numval = (long)tv_get_number_chk(varp, &error); ! strval = tv_get_string_buf_chk(varp, nbuf); ! if (!error && strval != NULL) ! set_option_value(varname, numval, strval, OPT_LOCAL); // reset notion of buffer aucmd_restbuf(&aco); --- 3778,3789 ---- { if (*varname == '&') { aco_save_T aco; // set curbuf to be our buf, temporarily aucmd_prepbuf(&aco, buf); ! set_option_from_tv(varname + 1, varp); // reset notion of buffer aucmd_restbuf(&aco); *** ../vim-8.2.1488/src/testdir/test_vim9_func.vim 2020-08-19 16:00:02.086372657 +0200 --- src/testdir/test_vim9_func.vim 2020-08-19 21:18:49.821508559 +0200 *************** *** 1391,1396 **** --- 1391,1408 ---- eval expand('.')->readdirex({e -> e.name[0] !=# '.'}) enddef + def Test_setbufvar() + setbufvar(bufnr('%'), '&syntax', 'vim') + assert_equal('vim', &syntax) + setbufvar(bufnr('%'), '&ts', 16) + assert_equal(16, &ts) + settabwinvar(1, 1, '&syntax', 'vam') + assert_equal('vam', &syntax) + settabwinvar(1, 1, '&ts', 15) + assert_equal(15, &ts) + setlocal ts=8 + enddef + def Fibonacci(n: number): number if n < 2 return n *** ../vim-8.2.1488/src/version.c 2020-08-19 20:19:27.133486043 +0200 --- src/version.c 2020-08-19 21:07:41.385458337 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1489, /**/ -- "Marriage is the process of finding out what kind of man your wife would have preferred" /// 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 ///