Patch 8.2.3129
Problem: Vim9: imported uninitialized list does not get type checked.
Solution: Get type from imported variable.
Files: src/eval.c, src/evalvars.c, src/vim9script.c,
src/proto/vim9script.pro, src/userfunc.c,
src/testdir/test_vim9_script.vim
*** ../vim-8.2.3128/src/eval.c 2021-07-08 20:57:14.542398410 +0200
--- src/eval.c 2021-07-08 21:26:58.900137105 +0200
***************
*** 959,965 ****
&& lp->ll_tv == &v->di_tv
&& ht != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(lp->ll_tv, TRUE);
// Vim9 script local variable: get the type
if (sv != NULL)
--- 959,965 ----
&& lp->ll_tv == &v->di_tv
&& ht != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(lp->ll_tv);
// Vim9 script local variable: get the type
if (sv != NULL)
*** ../vim-8.2.3128/src/evalvars.c 2021-07-08 20:57:14.542398410 +0200
--- src/evalvars.c 2021-07-08 21:27:47.020076557 +0200
***************
*** 2564,2572 ****
int ret = OK;
typval_T *tv = NULL;
int found = FALSE;
- dictitem_T *v;
hashtab_T *ht = NULL;
int cc;
// truncate the name, so that we can use strcmp()
cc = name[len];
--- 2564,2572 ----
int ret = OK;
typval_T *tv = NULL;
int found = FALSE;
hashtab_T *ht = NULL;
int cc;
+ type_T *type = NULL;
// truncate the name, so that we can use strcmp()
cc = name[len];
***************
*** 2576,2588 ****
if ((tv = lookup_debug_var(name)) == NULL)
{
// Check for user-defined variables.
! v = find_var(name, &ht, flags & EVAL_VAR_NOAUTOLOAD);
if (v != NULL)
{
tv = &v->di_tv;
if (dip != NULL)
*dip = v;
}
}
if (tv == NULL && (in_vim9script() || STRNCMP(name, "s:", 2) == 0))
--- 2576,2591 ----
if ((tv = lookup_debug_var(name)) == NULL)
{
// Check for user-defined variables.
! dictitem_T *v = find_var(name, &ht, flags & EVAL_VAR_NOAUTOLOAD);
!
if (v != NULL)
{
tv = &v->di_tv;
if (dip != NULL)
*dip = v;
}
+ else
+ ht = NULL;
}
if (tv == NULL && (in_vim9script() || STRNCMP(name, "s:", 2) == 0))
***************
*** 2628,2633 ****
--- 2631,2637 ----
svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
+ import->imp_var_vals_idx;
tv = sv->sv_tv;
+ type = sv->sv_type;
}
}
else if (in_vim9script())
***************
*** 2656,2668 ****
}
else if (rettv != NULL)
{
- type_T *type = NULL;
-
if (ht != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(tv, FALSE);
- // TODO: check imported variable
if (sv != NULL)
type = sv->sv_type;
}
--- 2660,2669 ----
}
else if (rettv != NULL)
{
if (ht != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(tv);
if (sv != NULL)
type = sv->sv_type;
}
*** ../vim-8.2.3128/src/vim9script.c 2021-07-08 20:57:14.542398410 +0200
--- src/vim9script.c 2021-07-08 21:28:34.572016502 +0200
***************
*** 616,622 ****
if (idx < 0 && ufunc == NULL)
goto erret;
! // If already imported with the same propertis and the
// IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create
// a new one (and give an error for an existing import).
imported = find_imported(name, len, cctx);
--- 616,622 ----
if (idx < 0 && ufunc == NULL)
goto erret;
! // If already imported with the same properties and the
// IMP_FLAGS_RELOAD set then we keep that entry. Otherwise create
// a new one (and give an error for an existing import).
imported = find_imported(name, len, cctx);
***************
*** 806,812 ****
}
else
{
! sv = find_typval_in_script(&di->di_tv, TRUE);
}
if (sv != NULL)
{
--- 806,812 ----
}
else
{
! sv = find_typval_in_script(&di->di_tv);
}
if (sv != NULL)
{
***************
*** 922,932 ****
/*
* Find the script-local variable that links to "dest".
! * Returns NULL if not found and when "give_error" is TRUE this is considered
! * an internal error.
*/
svar_T *
! find_typval_in_script(typval_T *dest, int give_error)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
int idx;
--- 922,931 ----
/*
* Find the script-local variable that links to "dest".
! * Returns NULL if not found and give an internal error.
*/
svar_T *
! find_typval_in_script(typval_T *dest)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
int idx;
***************
*** 945,952 ****
if (sv->sv_name != NULL && sv->sv_tv == dest)
return sv;
}
! if (give_error)
! iemsg("find_typval_in_script(): not found");
return NULL;
}
--- 944,950 ----
if (sv->sv_name != NULL && sv->sv_tv == dest)
return sv;
}
! iemsg("find_typval_in_script(): not found");
return NULL;
}
***************
*** 961,967 ****
char_u *name,
where_T where)
{
! svar_T *sv = find_typval_in_script(dest, TRUE);
int ret;
if (sv != NULL)
--- 959,965 ----
char_u *name,
where_T where)
{
! svar_T *sv = find_typval_in_script(dest);
int ret;
if (sv != NULL)
*** ../vim-8.2.3128/src/proto/vim9script.pro 2021-07-08 20:57:14.542398410
+0200
--- src/proto/vim9script.pro 2021-07-08 21:28:40.976008405 +0200
***************
*** 16,22 ****
void update_vim9_script_var(int create, dictitem_T *di, int flags, typval_T
*tv, type_T **type, int do_member);
void hide_script_var(scriptitem_T *si, int idx, int func_defined);
void free_all_script_vars(scriptitem_T *si);
! svar_T *find_typval_in_script(typval_T *dest, int give_error);
int check_script_var_type(typval_T *dest, typval_T *value, char_u *name,
where_T where);
int check_reserved_name(char_u *name);
/* vim: set ft=c : */
--- 16,22 ----
void update_vim9_script_var(int create, dictitem_T *di, int flags, typval_T
*tv, type_T **type, int do_member);
void hide_script_var(scriptitem_T *si, int idx, int func_defined);
void free_all_script_vars(scriptitem_T *si);
! svar_T *find_typval_in_script(typval_T *dest);
int check_script_var_type(typval_T *dest, typval_T *value, char_u *name,
where_T where);
int check_reserved_name(char_u *name);
/* vim: set ft=c : */
*** ../vim-8.2.3128/src/userfunc.c 2021-07-08 20:57:14.542398410 +0200
--- src/userfunc.c 2021-07-08 21:27:54.128067590 +0200
***************
*** 1512,1518 ****
{
if (type != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(&v->di_tv, TRUE);
if (sv != NULL)
*type = sv->sv_type;
--- 1512,1518 ----
{
if (type != NULL && ht == get_script_local_ht())
{
! svar_T *sv = find_typval_in_script(&v->di_tv);
if (sv != NULL)
*type = sv->sv_type;
*** ../vim-8.2.3128/src/testdir/test_vim9_script.vim 2021-07-08
19:22:09.238611461 +0200
--- src/testdir/test_vim9_script.vim 2021-07-08 21:30:03.999903045 +0200
***************
*** 1391,1396 ****
--- 1391,1397 ----
vim9script
export var one = 1
export var yes = 'yes'
+ export var slist: list<string>
END
writefile(export_lines, 'XexportAs')
***************
*** 1415,1420 ****
--- 1416,1428 ----
END
CheckScriptSuccess(import_lines)
+ import_lines =<< trim END
+ vim9script
+ import {slist as impSlist} from './XexportAs'
+ impSlist->add(123)
+ END
+ CheckScriptFailure(import_lines, 'E1012: Type mismatch; expected string but
got number')
+
delete('XexportAs')
enddef
***************
*** 1947,1954 ****
'g:imported_rtp = exported',
]
writefile(import_lines, 'Ximport_rtp.vim')
! mkdir('import')
! writefile(s:export_script_lines, 'import/Xexport_rtp.vim')
var save_rtp = &rtp
&rtp = getcwd()
--- 1955,1962 ----
'g:imported_rtp = exported',
]
writefile(import_lines, 'Ximport_rtp.vim')
! mkdir('Ximport')
! writefile(s:export_script_lines, 'Ximport/Xexport_rtp.vim')
var save_rtp = &rtp
&rtp = getcwd()
***************
*** 1960,1966 ****
Undo_export_script_lines()
unlet g:imported_rtp
delete('Ximport_rtp.vim')
! delete('import', 'rf')
enddef
def Test_import_compile_error()
--- 1968,1974 ----
Undo_export_script_lines()
unlet g:imported_rtp
delete('Ximport_rtp.vim')
! delete('Ximport', 'rf')
enddef
def Test_import_compile_error()
*** ../vim-8.2.3128/src/version.c 2021-07-08 20:57:14.542398410 +0200
--- src/version.c 2021-07-08 21:19:22.908694086 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3129,
/**/
--
hundred-and-one symptoms of being an internet addict:
97. Your mother tells you to remember something, and you look for
a File/Save command.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202107081939.168JdXnN098553%40masaka.moolenaar.net.