comparison src/eval.c @ 26990:4b8d836db103 v8.2.4024

patch 8.2.4024: confusing error message if imported name is used directly Commit: https://github.com/vim/vim/commit/32884ad753ffb462d27998beb50678888209075f Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 7 12:45:29 2022 +0000 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jan 2022 14:00:04 +0100
parents 8796f1384750
children 268f6a3511df
comparison
equal deleted inserted replaced
26989:e6c75e80cb49 26990:4b8d836db103
3479 { 3479 {
3480 int evaluate = evalarg != NULL 3480 int evaluate = evalarg != NULL
3481 && (evalarg->eval_flags & EVAL_EVALUATE); 3481 && (evalarg->eval_flags & EVAL_EVALUATE);
3482 int len; 3482 int len;
3483 char_u *s; 3483 char_u *s;
3484 char_u *name_start = NULL;
3484 char_u *start_leader, *end_leader; 3485 char_u *start_leader, *end_leader;
3485 int ret = OK; 3486 int ret = OK;
3486 char_u *alias; 3487 char_u *alias;
3487 3488
3488 /* 3489 /*
3711 rettv->v_type = VAR_SPECIAL; 3712 rettv->v_type = VAR_SPECIAL;
3712 rettv->vval.v_number = VVAL_NULL; 3713 rettv->vval.v_number = VVAL_NULL;
3713 ret = OK; 3714 ret = OK;
3714 } 3715 }
3715 else 3716 else
3717 {
3718 name_start = s;
3716 ret = eval_variable(s, len, 0, rettv, NULL, 3719 ret = eval_variable(s, len, 0, rettv, NULL,
3717 EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT); 3720 EVAL_VAR_VERBOSE + EVAL_VAR_IMPORT);
3721 }
3718 } 3722 }
3719 else 3723 else
3720 { 3724 {
3721 // skip the name 3725 // skip the name
3722 check_vars(s, len); 3726 check_vars(s, len);
3727 } 3731 }
3728 3732
3729 // Handle following '[', '(' and '.' for expr[expr], expr.name, 3733 // Handle following '[', '(' and '.' for expr[expr], expr.name,
3730 // expr(expr), expr->name(expr) 3734 // expr(expr), expr->name(expr)
3731 if (ret == OK) 3735 if (ret == OK)
3732 ret = handle_subscript(arg, rettv, evalarg, TRUE); 3736 ret = handle_subscript(arg, name_start, rettv, evalarg, TRUE);
3733 3737
3734 /* 3738 /*
3735 * Apply logical NOT and unary '-', from right to left, ignore '+'. 3739 * Apply logical NOT and unary '-', from right to left, ignore '+'.
3736 */ 3740 */
3737 if (ret == OK && evaluate && end_leader > start_leader) 3741 if (ret == OK && evaluate && end_leader > start_leader)
5889 * - ".name" lookup 5893 * - ".name" lookup
5890 * - function call with Funcref variable: func(expr) 5894 * - function call with Funcref variable: func(expr)
5891 * - method call: var->method() 5895 * - method call: var->method()
5892 * 5896 *
5893 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len() 5897 * Can all be combined in any order: dict.func(expr)[idx]['func'](expr)->len()
5898 * "name_start" points to a variable before the subscript or is NULL.
5894 */ 5899 */
5895 int 5900 int
5896 handle_subscript( 5901 handle_subscript(
5897 char_u **arg, 5902 char_u **arg,
5903 char_u *name_start,
5898 typval_T *rettv, 5904 typval_T *rettv,
5899 evalarg_T *evalarg, 5905 evalarg_T *evalarg,
5900 int verbose) // give error messages 5906 int verbose) // give error messages
5901 { 5907 {
5902 int evaluate = evalarg != NULL 5908 int evaluate = evalarg != NULL
5934 // Found script from "import {name} as name", script item name must 5940 // Found script from "import {name} as name", script item name must
5935 // follow. 5941 // follow.
5936 if (**arg != '.') 5942 if (**arg != '.')
5937 { 5943 {
5938 if (verbose) 5944 if (verbose)
5939 semsg(_(e_expected_str_but_got_str), "'.'", *arg); 5945 semsg(_(e_expected_dot_after_name_str),
5946 name_start != NULL ? name_start: *arg);
5940 ret = FAIL; 5947 ret = FAIL;
5941 break; 5948 break;
5942 } 5949 }
5943 ++*arg; 5950 ++*arg;
5944 if (IS_WHITE_OR_NUL(**arg)) 5951 if (IS_WHITE_OR_NUL(**arg))