To: vim_dev@googlegroups.com Subject: Patch 8.2.4330 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4330 Problem: Vim9: no error if script imports itself. Solution: Give an error when a script imports itself. Files: src/vim9script.c, src/errors.h, src/testdir/test_vim9_import.vim *** ../vim-8.2.4329/src/vim9script.c 2022-01-26 16:45:16.934506694 +0000 --- src/vim9script.c 2022-02-08 19:03:01.684175693 +0000 *************** *** 516,521 **** --- 516,527 ---- goto erret; } + if (sid == current_sctx.sc_sid) + { + emsg(_(e_script_cannot_import_itself)); + goto erret; + } + import_gap = gap != NULL ? gap : &SCRIPT_ITEM(import_sid)->sn_imports; for (i = 0; i < import_gap->ga_len; ++i) { *** ../vim-8.2.4329/src/errors.h 2022-02-07 21:53:58.085529486 +0000 --- src/errors.h 2022-02-08 19:02:40.700136333 +0000 *************** *** 2802,2808 **** INIT(= N_("E1086: Function reference invalid")); EXTERN char e_cannot_use_index_when_declaring_variable[] INIT(= N_("E1087: Cannot use an index when declaring a variable")); ! // E1088 unused EXTERN char e_unknown_variable_str[] INIT(= N_("E1089: Unknown variable: %s")); EXTERN char e_cannot_assign_to_argument[] --- 2802,2809 ---- INIT(= N_("E1086: Function reference invalid")); EXTERN char e_cannot_use_index_when_declaring_variable[] INIT(= N_("E1087: Cannot use an index when declaring a variable")); ! EXTERN char e_script_cannot_import_itself[] ! INIT(= N_("E1088: Script cannot import itself")); EXTERN char e_unknown_variable_str[] INIT(= N_("E1089: Unknown variable: %s")); EXTERN char e_cannot_assign_to_argument[] *** ../vim-8.2.4329/src/testdir/test_vim9_import.vim 2022-02-06 13:08:37.467920903 +0000 --- src/testdir/test_vim9_import.vim 2022-02-08 19:10:18.116578563 +0000 *************** *** 500,506 **** v9.CheckScriptFailure(lines, 'E1262:') delete('Xthat.vim') ! mkdir('Ximport') writefile(['vim9script'], 'Ximport/.vim') --- 500,515 ---- v9.CheckScriptFailure(lines, 'E1262:') delete('Xthat.vim') ! ! lines =<< trim END ! vim9script ! export var item = 'hello' ! import './Xyourself.vim' ! END ! writefile(lines, 'Xyourself.vim') ! assert_fails('source Xyourself.vim', 'E1088:') ! delete('Xyourself.vim') ! mkdir('Ximport') writefile(['vim9script'], 'Ximport/.vim') *** ../vim-8.2.4329/src/version.c 2022-02-08 18:08:49.940360054 +0000 --- src/version.c 2022-02-08 19:04:19.360301691 +0000 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4330, /**/ -- How To Keep A Healthy Level Of Insanity: 1. At lunch time, sit in your parked car with sunglasses on and point a hair dryer at passing cars. See if they slow down. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///