changeset 25298:90fa50a31994 v8.2.3186

patch 8.2.3186: Vim9: not all failures for import tested Commit: https://github.com/vim/vim/commit/605793500b351ee92483d04b1e03fb8af30dd101 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 19 21:45:07 2021 +0200 patch 8.2.3186: Vim9: not all failures for import tested Problem: Vim9: not all failures for import tested Solution: Test more import failures
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Jul 2021 22:00:05 +0200
parents f5985274cf98
children a1eb85c2e0a5
files src/errors.h src/evalvars.c src/testdir/test_vim9_script.vim src/version.c
diffstat 4 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -511,7 +511,7 @@ EXTERN char e_list_required_for_argument
 EXTERN char e_bool_required_for_argument_nr[]
 	INIT(= N_("E1212: Bool required for argument %d"));
 EXTERN char e_redefining_imported_item_str[]
-	INIT(= N_("E1213: Redefining imported item %s"));
+	INIT(= N_("E1213: Redefining imported item \"%s\""));
 #if defined(FEAT_DIGRAPHS) && defined(FEAT_EVAL)
 EXTERN char e_digraph_must_be_just_two_characters_str[]
 	INIT(= N_("E1214: Digraph must be just two characters: %s"));
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3250,6 +3250,7 @@ set_var_const(
 	{
 	    scriptitem_T    *si = SCRIPT_ITEM(import->imp_sid);
 	    svar_T	    *sv;
+	    where_T	    where;
 
 	    // imported variable from another script
 	    if ((flags & ASSIGN_NO_DECL) == 0)
@@ -3257,10 +3258,16 @@ set_var_const(
 		semsg(_(e_redefining_imported_item_str), name);
 		goto failed;
 	    }
-	    sv = ((svar_T *)si->sn_var_vals.ga_data)
-						    + import->imp_var_vals_idx;
-	    // TODO: check the type
-	    // TODO: check for const and locked
+	    sv = ((svar_T *)si->sn_var_vals.ga_data) + import->imp_var_vals_idx;
+
+	    where.wt_index = 0;
+	    where.wt_variable = TRUE;
+	    if (check_typval_type(sv->sv_type, tv, where) == FAIL
+		    || value_check_lock(sv->sv_tv->v_lock, name, FALSE))
+	    {
+		goto failed;
+	    }
+
 	    dest_tv = sv->sv_tv;
 	    clear_tv(dest_tv);
 	}
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1375,6 +1375,30 @@ def Test_vim9_import_export()
   writefile(import_missing_comma_lines, 'Ximport3.vim')
   assert_fails('source Ximport3.vim', 'E1046:', '', 2, 'Ximport3.vim')
 
+  var import_redefining_lines =<< trim END
+    vim9script
+    import exported from './Xexport.vim'
+    var exported = 5
+  END
+  writefile(import_redefining_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1213: Redefining imported item "exported"', '', 3)
+
+  var import_assign_wrong_type_lines =<< trim END
+    vim9script
+    import exported from './Xexport.vim'
+    exported = 'xxx'
+  END
+  writefile(import_assign_wrong_type_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1012: Type mismatch; expected number but got string', '', 3)
+
+  var import_assign_const_lines =<< trim END
+    vim9script
+    import CONST from './Xexport.vim'
+    CONST = 4321
+  END
+  writefile(import_assign_const_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E741: Value is locked: CONST', '', 3)
+
   delete('Ximport.vim')
   delete('Ximport3.vim')
   delete('Xexport.vim')
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3186,
+/**/
     3185,
 /**/
     3184,