mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.1459: Vim9: declaring script var in script does not infer the type
Problem: Vim9: declaring ascript variable at the script level does not infer the type. Solution: Get the type from the value. (closes #6716)
This commit is contained in:
parent
9a5c553f79
commit
53b29e4845
@ -3049,7 +3049,10 @@ set_var_const(
|
|||||||
+ si->sn_var_vals.ga_len;
|
+ si->sn_var_vals.ga_len;
|
||||||
sv->sv_name = di->di_key;
|
sv->sv_name = di->di_key;
|
||||||
sv->sv_tv = &di->di_tv;
|
sv->sv_tv = &di->di_tv;
|
||||||
sv->sv_type = type == NULL ? &t_any : type;
|
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_const = (flags & LET_IS_CONST);
|
||||||
sv->sv_export = is_export;
|
sv->sv_export = is_export;
|
||||||
++si->sn_var_vals.ga_len;
|
++si->sn_var_vals.ga_len;
|
||||||
|
@ -2914,12 +2914,20 @@ def Test_let_declaration()
|
|||||||
let s:other: number
|
let s:other: number
|
||||||
other = 1234
|
other = 1234
|
||||||
g:other_var = other
|
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
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
assert_equal('', g:var_uninit)
|
assert_equal('', g:var_uninit)
|
||||||
assert_equal('text', g:var_test)
|
assert_equal('text', g:var_test)
|
||||||
assert_equal('prefixed', g:var_prefixed)
|
assert_equal('prefixed', g:var_prefixed)
|
||||||
assert_equal(1234, g:other_var)
|
assert_equal(1234, g:other_var)
|
||||||
|
assert_equal(222, g:dict_val)
|
||||||
|
|
||||||
unlet g:var_uninit
|
unlet g:var_uninit
|
||||||
unlet g:var_test
|
unlet g:var_test
|
||||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1459,
|
||||||
/**/
|
/**/
|
||||||
1458,
|
1458,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user