To: vim_dev@googlegroups.com Subject: Patch 8.2.1459 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1459 Problem: Vim9: declaring ascript variable at the script level does not infer the type. Solution: Get the type from the value. (closes #6716) Files: src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1458/src/evalvars.c 2020-08-13 22:47:20.373992741 +0200 --- src/evalvars.c 2020-08-15 14:30:07.127837383 +0200 *************** *** 3049,3055 **** + si->sn_var_vals.ga_len; sv->sv_name = di->di_key; sv->sv_tv = &di->di_tv; ! sv->sv_type = type == NULL ? &t_any : type; sv->sv_const = (flags & LET_IS_CONST); sv->sv_export = is_export; ++si->sn_var_vals.ga_len; --- 3049,3058 ---- + si->sn_var_vals.ga_len; sv->sv_name = di->di_key; sv->sv_tv = &di->di_tv; ! if (type == NULL) ! sv->sv_type = typval2type(tv, &si->sn_type_list); ! else ! sv->sv_type = type; sv->sv_const = (flags & LET_IS_CONST); sv->sv_export = is_export; ++si->sn_var_vals.ga_len; *** ../vim-8.2.1458/src/testdir/test_vim9_script.vim 2020-08-14 20:52:25.174495868 +0200 --- src/testdir/test_vim9_script.vim 2020-08-15 14:29:07.948285289 +0200 *************** *** 2914,2925 **** --- 2914,2933 ---- let s:other: number other = 1234 g:other_var = other + + # type is inferred + s:dict = {'a': 222} + def GetDictVal(key: any) + g:dict_val = s:dict[key] + enddef + GetDictVal('a') END CheckScriptSuccess(lines) assert_equal('', g:var_uninit) assert_equal('text', g:var_test) assert_equal('prefixed', g:var_prefixed) assert_equal(1234, g:other_var) + assert_equal(222, g:dict_val) unlet g:var_uninit unlet g:var_test *** ../vim-8.2.1458/src/version.c 2020-08-15 14:07:19.578165841 +0200 --- src/version.c 2020-08-15 14:26:41.025436841 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1459, /**/ -- "You mean there really is an answer?" "Yes! But you're not going to like it!" "Oh do please tell us!" "You're really not going to like it!" "but we MUST know - tell us" "Alright, the answer is...." "yes..." "... is ..." "yes... come on!" "is 42!" (Douglas Adams - The Hitchhiker's Guide to the Galaxy) /// 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 ///