Skip to content

Commit 6853c38

Browse files
committed
patch 8.2.3411: Vim9: crash when using base name of import
Problem: Vim9: crash when using base name of import. (Naohiro Ono) Solution: Check the import flags. (closes #8843)
1 parent 89a54b4 commit 6853c38

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,5 @@ EXTERN char e_legacy_must_be_followed_by_command[]
654654
INIT(= N_("E1234: legacy must be followed by a command"));
655655
EXTERN char e_function_reference_is_not_set[]
656656
INIT(= N_("E1235: Function reference is not set"));
657+
EXTERN char e_cannot_use_str_itself_it_is_imported_with_star[]
658+
INIT(= N_("E1236: Cannot use %s itself, it is imported with '*'"));

src/evalvars.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,12 @@ set_var_const(
32603260
semsg(_(e_redefining_imported_item_str), name);
32613261
goto failed;
32623262
}
3263+
if (import->imp_flags & IMP_FLAGS_STAR)
3264+
{
3265+
semsg(_(e_cannot_use_str_itself_it_is_imported_with_star),
3266+
name);
3267+
goto failed;
3268+
}
32633269
sv = ((svar_T *)si->sn_var_vals.ga_data) + import->imp_var_vals_idx;
32643270

32653271
where.wt_variable = TRUE;

src/testdir/test_vim9_script.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,21 @@ def Test_vim9_import_export()
14771477
delete('Xvim9_script')
14781478
enddef
14791479

1480+
def Test_import_star_fails()
1481+
writefile([], 'Xfoo.vim')
1482+
var lines =<< trim END
1483+
import * as foo from '/tmp/foo.vim'
1484+
foo = 'bar'
1485+
END
1486+
CheckDefAndScriptFailure2(lines, 'E1094:', 'E1236: Cannot use foo itself')
1487+
lines =<< trim END
1488+
vim9script
1489+
import * as foo from '/tmp/foo.vim'
1490+
var that = foo
1491+
END
1492+
CheckScriptFailure(lines, 'E1029: Expected ''.''')
1493+
enddef
1494+
14801495
def Test_import_as()
14811496
var export_lines =<< trim END
14821497
vim9script

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3411,
758760
/**/
759761
3410,
760762
/**/

0 commit comments

Comments
 (0)