forked from aniani/vim
patch 8.2.4024: confusing error message if imported name is used directly
Problem: Confusing error message if imported name is used directly. Solution: Give a better error message.
This commit is contained in:
11
src/eval.c
11
src/eval.c
@@ -3481,6 +3481,7 @@ eval7(
|
|||||||
&& (evalarg->eval_flags & EVAL_EVALUATE);
|
&& (evalarg->eval_flags & EVAL_EVALUATE);
|
||||||
int len;
|
int len;
|
||||||
char_u *s;
|
char_u *s;
|
||||||
|
char_u *name_start = NULL;
|
||||||
char_u *start_leader, *end_leader;
|
char_u *start_leader, *end_leader;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
char_u *alias;
|
char_u *alias;
|
||||||
@@ -3713,9 +3714,12 @@ eval7(
|
|||||||
ret = OK;
|
ret = OK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
name_start = s;
|
||||||
ret = eval_variable(s, len, 0, rettv, NULL,
|
ret = eval_variable(s, len, 0, rettv, NULL,
|
||||||
EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT);
|
EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// skip the name
|
// skip the name
|
||||||
@@ -3729,7 +3733,7 @@ eval7(
|
|||||||
// Handle following '[', '(' and '.' for expr[expr], expr.name,
|
// Handle following '[', '(' and '.' for expr[expr], expr.name,
|
||||||
// expr(expr), expr->name(expr)
|
// expr(expr), expr->name(expr)
|
||||||
if (ret == OK)
|
if (ret == OK)
|
||||||
ret = handle_subscript(arg, rettv, evalarg, TRUE);
|
ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply logical NOT and unary '-', from right to left, ignore '+'.
|
* Apply logical NOT and unary '-', from right to left, ignore '+'.
|
||||||
@@ -5891,10 +5895,12 @@ eval_isdictc(int c)
|
|||||||
* - method call: var->method()
|
* - method call: var->method()
|
||||||
*
|
*
|
||||||
* Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
|
* 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
|
int
|
||||||
handle_subscript(
|
handle_subscript(
|
||||||
char_u **arg,
|
char_u **arg,
|
||||||
|
char_u *name_start,
|
||||||
typval_T *rettv,
|
typval_T *rettv,
|
||||||
evalarg_T *evalarg,
|
evalarg_T *evalarg,
|
||||||
int verbose) // give error messages
|
int verbose) // give error messages
|
||||||
@@ -5936,7 +5942,8 @@ handle_subscript(
|
|||||||
if (**arg != '.')
|
if (**arg != '.')
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
semsg(_(e_expected_str_but_got_str), "'.'", *arg);
|
semsg(_(e_expected_dot_after_name_str),
|
||||||
|
name_start != NULL ? name_start: *arg);
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -1239,8 +1239,8 @@ list_arg_vars(exarg_T *eap, char_u *arg, int *first)
|
|||||||
{
|
{
|
||||||
// handle d.key, l[idx], f(expr)
|
// handle d.key, l[idx], f(expr)
|
||||||
arg_subsc = arg;
|
arg_subsc = arg;
|
||||||
if (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, TRUE)
|
if (handle_subscript(&arg, name_start, &tv,
|
||||||
== FAIL)
|
&EVALARG_EVALUATE, TRUE) == FAIL)
|
||||||
error = TRUE;
|
error = TRUE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -3955,7 +3955,8 @@ var_exists(char_u *var)
|
|||||||
{
|
{
|
||||||
// handle d.key, l[idx], f(expr)
|
// handle d.key, l[idx], f(expr)
|
||||||
arg = skipwhite(arg);
|
arg = skipwhite(arg);
|
||||||
n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK);
|
n = (handle_subscript(&arg, name, &tv, &EVALARG_EVALUATE,
|
||||||
|
FALSE) == OK);
|
||||||
if (n)
|
if (n)
|
||||||
clear_tv(&tv);
|
clear_tv(&tv);
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end, int f
|
|||||||
int eval_isnamec(int c);
|
int eval_isnamec(int c);
|
||||||
int eval_isnamec1(int c);
|
int eval_isnamec1(int c);
|
||||||
int eval_isdictc(int c);
|
int eval_isdictc(int c);
|
||||||
int handle_subscript(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int verbose);
|
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);
|
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 echo_one(typval_T *rettv, int with_space, int *atstart, int *needclr);
|
||||||
void ex_echo(exarg_T *eap);
|
void ex_echo(exarg_T *eap);
|
||||||
|
@@ -1265,6 +1265,26 @@ def Test_vim9_import_export()
|
|||||||
unlet g:imported_func
|
unlet g:imported_func
|
||||||
delete('Ximport_lbr.vim')
|
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
|
var import_star_as_lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
import './Xexport.vim' as Export
|
import './Xexport.vim' as Export
|
||||||
@@ -1333,7 +1353,7 @@ def Test_vim9_import_export()
|
|||||||
g:imported_script = Export exported
|
g:imported_script = Export exported
|
||||||
END
|
END
|
||||||
writefile(import_star_as_lines_script_no_dot, 'Ximport.vim')
|
writefile(import_star_as_lines_script_no_dot, 'Ximport.vim')
|
||||||
assert_fails('source Ximport.vim', 'E1029:')
|
assert_fails('source Ximport.vim', 'E1060: Expected dot after name: Export exported')
|
||||||
|
|
||||||
var import_star_as_lines_script_space_after_dot =<< trim END
|
var import_star_as_lines_script_space_after_dot =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@@ -1519,7 +1539,7 @@ def Test_import_star_fails()
|
|||||||
import './Xfoo.vim' as foo
|
import './Xfoo.vim' as foo
|
||||||
var that = foo
|
var that = foo
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1029: Expected ''.''')
|
CheckScriptFailure(lines, 'E1060: Expected dot after name: foo')
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -5170,7 +5170,7 @@ ex_call(exarg_T *eap)
|
|||||||
dbg_check_breakpoint(eap);
|
dbg_check_breakpoint(eap);
|
||||||
|
|
||||||
// Handle a function returning a Funcref, Dictionary or List.
|
// Handle a function returning a Funcref, Dictionary or List.
|
||||||
if (handle_subscript(&arg, &rettv,
|
if (handle_subscript(&arg, NULL, &rettv,
|
||||||
eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL)
|
eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL)
|
||||||
{
|
{
|
||||||
failed = TRUE;
|
failed = TRUE;
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4024,
|
||||||
/**/
|
/**/
|
||||||
4023,
|
4023,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user