]> granicus.if.org Git - vim/commitdiff
patch 8.2.3411: Vim9: crash when using base name of import v8.2.3411
authorBram Moolenaar <Bram@vim.org>
Tue, 7 Sep 2021 20:12:19 +0000 (22:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 Sep 2021 20:12:19 +0000 (22:12 +0200)
Problem:    Vim9: crash when using base name of import. (Naohiro Ono)
Solution:   Check the import flags. (closes #8843)

src/errors.h
src/evalvars.c
src/testdir/test_vim9_script.vim
src/version.c

index b4c111d3f1932028a816847aeccd726663d58ef8..dd72a74a9dfa92359770164357c837e335f80a46 100644 (file)
@@ -654,3 +654,5 @@ EXTERN char e_legacy_must_be_followed_by_command[]
        INIT(= N_("E1234: legacy must be followed by a command"));
 EXTERN char e_function_reference_is_not_set[]
        INIT(= N_("E1235: Function reference is not set"));
+EXTERN char e_cannot_use_str_itself_it_is_imported_with_star[]
+       INIT(= N_("E1236: Cannot use %s itself, it is imported with '*'"));
index 1af9ec562843e86ae4fcff1b66dac3bb459df21b..5a26effbb31690d5d83104d6b4d63f37b1314eca 100644 (file)
@@ -3260,6 +3260,12 @@ set_var_const(
                semsg(_(e_redefining_imported_item_str), name);
                goto failed;
            }
+           if (import->imp_flags & IMP_FLAGS_STAR)
+           {
+               semsg(_(e_cannot_use_str_itself_it_is_imported_with_star),
+                                                                        name);
+               goto failed;
+           }
            sv = ((svar_T *)si->sn_var_vals.ga_data) + import->imp_var_vals_idx;
 
            where.wt_variable = TRUE;
index cdbf914ab7664e1339f2b017a86a81b0b3290ea1..8341ef192baaa33c89f19169b5dc568e90026c6a 100644 (file)
@@ -1477,6 +1477,21 @@ def Test_vim9_import_export()
   delete('Xvim9_script')
 enddef
 
+def Test_import_star_fails()
+  writefile([], 'Xfoo.vim')
+  var lines =<< trim END
+      import * as foo from '/tmp/foo.vim'
+      foo = 'bar'
+  END
+  CheckDefAndScriptFailure2(lines, 'E1094:', 'E1236: Cannot use foo itself')
+  lines =<< trim END
+      vim9script
+      import * as foo from '/tmp/foo.vim'
+      var that = foo
+  END
+  CheckScriptFailure(lines, 'E1029: Expected ''.''')
+enddef
+
 def Test_import_as()
   var export_lines =<< trim END
     vim9script
index 979c039baf85f1979320e5fd01b087589d8627f0..e5facbaa5201092fa30009e616d0ff15ba36afe1 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3411,
 /**/
     3410,
 /**/