To: vim_dev@googlegroups.com Subject: Patch 8.2.4083 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4083 Problem: Vim9: no test for "vim9script autoload' and using script variable in the same script. Solution: Add a simple test. Fix uncovered problem. Files: src/evalvars.c, src/testdir/test_vim9_import.vim *** ../vim-8.2.4082/src/evalvars.c 2022-01-10 18:06:58.686381782 +0000 --- src/evalvars.c 2022-01-13 20:15:47.912840556 +0000 *************** *** 2874,2879 **** --- 2874,2905 ---- } } + // When using "vim9script autoload" script-local items are prefixed but can + // be used with s:name. + if (SCRIPT_ID_VALID(current_sctx.sc_sid) + && name[0] == 's' && name[1] == ':') + { + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); + + if (si->sn_autoload_prefix != NULL) + { + char_u *auto_name = concat_str(si->sn_autoload_prefix, name + 2); + + if (auto_name != NULL) + { + ht = &globvarht; + ret = find_var_in_ht(ht, *name, auto_name, TRUE); + if (ret != NULL) + { + if (htp != NULL) + *htp = ht; + return ret; + } + } + vim_free(auto_name); + } + } + return NULL; } *************** *** 3318,3324 **** } /* ! * Set variable "name" to value in "tv". * When "sid" is non-zero "name" is in the script with this ID. * If the variable already exists and "is_const" is FALSE the value is updated. * Otherwise the variable is created. --- 3344,3350 ---- } /* ! * Set variable "name" to value in "tv_arg". * When "sid" is non-zero "name" is in the script with this ID. * If the variable already exists and "is_const" is FALSE the value is updated. * Otherwise the variable is created. *** ../vim-8.2.4082/src/testdir/test_vim9_import.vim 2022-01-13 19:25:44.003786906 +0000 --- src/testdir/test_vim9_import.vim 2022-01-13 20:16:30.672717392 +0000 *************** *** 1091,1097 **** enddef " test using an auto-loaded function and variable ! def Test_vim9_autoload() var lines =<< trim END vim9script def some#gettest(): string --- 1091,1097 ---- enddef " test using an auto-loaded function and variable ! def Test_vim9_autoload_full_name() var lines =<< trim END vim9script def some#gettest(): string *************** *** 1146,1156 **** return 'test' enddef ! export func GetMore() ! return Gettest() .. 'more' endfunc ! export var name = 'name' export final fname = 'final' export const cname = 'const' END --- 1146,1161 ---- return 'test' enddef ! export var name = 'name' ! ! export func GetFunc() ! return Gettest() .. 'more' .. s:name endfunc ! export def GetDef(): string ! return Gettest() .. 'more' .. name ! enddef ! export final fname = 'final' export const cname = 'const' END *************** *** 1165,1171 **** assert_equal('test', prefixed.Gettest()) assert_equal(1, g:prefixed_loaded) ! assert_equal('testmore', prefixed.GetMore()) assert_equal('name', prefixed.name) assert_equal('final', prefixed.fname) assert_equal('const', prefixed.cname) --- 1170,1177 ---- assert_equal('test', prefixed.Gettest()) assert_equal(1, g:prefixed_loaded) ! assert_equal('testmorename', prefixed.GetFunc()) ! assert_equal('testmorename', prefixed.GetDef()) assert_equal('name', prefixed.name) assert_equal('final', prefixed.fname) assert_equal('const', prefixed.cname) *************** *** 1178,1184 **** # can also get the items by autoload name lines =<< trim END call assert_equal('test', prefixed#Gettest()) ! call assert_equal('testmore', prefixed#GetMore()) call assert_equal('name', prefixed#name) call assert_equal('final', prefixed#fname) call assert_equal('const', prefixed#cname) --- 1184,1190 ---- # can also get the items by autoload name lines =<< trim END call assert_equal('test', prefixed#Gettest()) ! call assert_equal('testmorename', prefixed#GetFunc()) call assert_equal('name', prefixed#name) call assert_equal('final', prefixed#fname) call assert_equal('const', prefixed#cname) *** ../vim-8.2.4082/src/version.c 2022-01-13 19:25:44.003786906 +0000 --- src/version.c 2022-01-13 19:34:17.331572047 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4083, /**/ -- You were lucky to have a LAKE! There were a hundred and sixty of us living in a small shoebox in the middle of the road. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///