To: vim_dev@googlegroups.com Subject: Patch 8.2.4024 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4024 Problem: Confusing error message if imported name is used directly. Solution: Give a better error message. Files: src/eval.c, src/proto/eval.pro, src/evalvars.c, src/userfunc.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.4023/src/eval.c 2022-01-06 21:10:24.465027868 +0000 --- src/eval.c 2022-01-07 12:30:00.194105728 +0000 *************** *** 3481,3486 **** --- 3481,3487 ---- && (evalarg->eval_flags & EVAL_EVALUATE); int len; char_u *s; + char_u *name_start = NULL; char_u *start_leader, *end_leader; int ret = OK; char_u *alias; *************** *** 3713,3720 **** --- 3714,3724 ---- ret = OK; } else + { + name_start = s; ret = eval_variable(s, len, 0, rettv, NULL, EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT); + } } else { *************** *** 3729,3735 **** // Handle following '[', '(' and '.' for expr[expr], expr.name, // expr(expr), expr->name(expr) if (ret == OK) ! ret = handle_subscript(arg, rettv, evalarg, TRUE); /* * Apply logical NOT and unary '-', from right to left, ignore '+'. --- 3733,3739 ---- // Handle following '[', '(' and '.' for expr[expr], expr.name, // expr(expr), expr->name(expr) if (ret == OK) ! ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE); /* * Apply logical NOT and unary '-', from right to left, ignore '+'. *************** *** 5891,5900 **** --- 5895,5906 ---- * - method call: var->method() * * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() + * "name_start" points to a variable before the subscript or is NULL. */ int handle_subscript( char_u **arg, + char_u *name_start, typval_T *rettv, evalarg_T *evalarg, int verbose) // give error messages *************** *** 5936,5942 **** if (**arg != '.') { if (verbose) ! semsg(_(e_expected_str_but_got_str), "'.'", *arg); ret = FAIL; break; } --- 5942,5949 ---- if (**arg != '.') { if (verbose) ! semsg(_(e_expected_dot_after_name_str), ! name_start != NULL ? name_start: *arg); ret = FAIL; break; } *** ../vim-8.2.4023/src/proto/eval.pro 2022-01-06 21:10:24.465027868 +0000 --- src/proto/eval.pro 2022-01-07 12:32:13.029796241 +0000 *************** *** 70,76 **** int eval_isnamec(int c); int eval_isnamec1(int c); int eval_isdictc(int c); ! int handle_subscript(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int verbose); int item_copy(typval_T *from, typval_T *to, int deep, int copyID); void echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr); void ex_echo(exarg_T *eap); --- 70,76 ---- int eval_isnamec(int c); int eval_isnamec1(int c); int eval_isdictc(int c); ! int handle_subscript(char_u **arg, char_u *name_start, typval_T *rettv, evalarg_T *evalarg, int verbose); int item_copy(typval_T *from, typval_T *to, int deep, int copyID); void echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr); void ex_echo(exarg_T *eap); *** ../vim-8.2.4023/src/evalvars.c 2022-01-06 21:10:24.469027861 +0000 --- src/evalvars.c 2022-01-07 12:31:18.277924113 +0000 *************** *** 1239,1246 **** { // handle d.key, l[idx], f(expr) arg_subsc = arg; ! if (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, TRUE) ! == FAIL) error = TRUE; else { --- 1239,1246 ---- { // handle d.key, l[idx], f(expr) arg_subsc = arg; ! if (handle_subscript(&arg, name_start, &tv, ! &EVALARG_EVALUATE, TRUE) == FAIL) error = TRUE; else { *************** *** 3955,3961 **** { // handle d.key, l[idx], f(expr) arg = skipwhite(arg); ! n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK); if (n) clear_tv(&tv); } --- 3955,3962 ---- { // handle d.key, l[idx], f(expr) arg = skipwhite(arg); ! n = (handle_subscript(&arg, name, &tv, &EVALARG_EVALUATE, ! FALSE) == OK); if (n) clear_tv(&tv); } *** ../vim-8.2.4023/src/userfunc.c 2022-01-06 21:10:24.469027861 +0000 --- src/userfunc.c 2022-01-07 12:31:30.393895863 +0000 *************** *** 5170,5176 **** dbg_check_breakpoint(eap); // Handle a function returning a Funcref, Dictionary or List. ! if (handle_subscript(&arg, &rettv, eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL) { failed = TRUE; --- 5170,5176 ---- dbg_check_breakpoint(eap); // Handle a function returning a Funcref, Dictionary or List. ! if (handle_subscript(&arg, NULL, &rettv, eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL) { failed = TRUE; *** ../vim-8.2.4023/src/testdir/test_vim9_script.vim 2022-01-06 21:10:24.469027861 +0000 --- src/testdir/test_vim9_script.vim 2022-01-07 12:44:03.963670619 +0000 *************** *** 1265,1270 **** --- 1265,1290 ---- unlet g:imported_func delete('Ximport_lbr.vim') + var line_break_before_dot =<< trim END + vim9script + import './Xexport.vim' as expo + g:exported = expo + .exported + END + writefile(line_break_before_dot, 'Ximport_lbr_before_dot.vim') + assert_fails('source Ximport_lbr_before_dot.vim', 'E1060:', '', 3) + delete('Ximport_lbr_before_dot.vim') + + var line_break_after_dot =<< trim END + vim9script + import './Xexport.vim' as expo + g:exported = expo. + exported + END + writefile(line_break_after_dot, 'Ximport_lbr_after_dot.vim') + assert_fails('source Ximport_lbr_after_dot.vim', 'E1074:', '', 3) + delete('Ximport_lbr_after_dot.vim') + var import_star_as_lines =<< trim END vim9script import './Xexport.vim' as Export *************** *** 1333,1339 **** g:imported_script = Export exported END writefile(import_star_as_lines_script_no_dot, 'Ximport.vim') ! assert_fails('source Ximport.vim', 'E1029:') var import_star_as_lines_script_space_after_dot =<< trim END vim9script --- 1353,1359 ---- g:imported_script = Export exported END writefile(import_star_as_lines_script_no_dot, 'Ximport.vim') ! assert_fails('source Ximport.vim', 'E1060: Expected dot after name: Export exported') var import_star_as_lines_script_space_after_dot =<< trim END vim9script *************** *** 1519,1525 **** import './Xfoo.vim' as foo var that = foo END ! CheckScriptFailure(lines, 'E1029: Expected ''.''') lines =<< trim END vim9script --- 1539,1545 ---- import './Xfoo.vim' as foo var that = foo END ! CheckScriptFailure(lines, 'E1060: Expected dot after name: foo') lines =<< trim END vim9script *** ../vim-8.2.4023/src/version.c 2022-01-06 22:07:53.323887225 +0000 --- src/version.c 2022-01-07 12:32:04.717815662 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4024, /**/ -- Marriage isn't a word. It's a sentence. /// 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 ///