Mercurial > vim
changeset 21909:a211bca98bc3 v8.2.1504
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Commit: https://github.com/vim/vim/commit/7cb6fc29d067ed97c0b0c1d2d5767125ef9ae1ab
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 21 22:36:47 2020 +0200
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Problem: Vim9: white space checks are only done for a :def function.
Solution: Also do checks at the script level. Adjust the name of a few
error messages.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 21 Aug 2020 22:45:03 +0200 |
parents | 9f0b9a678704 |
children | f40e79100c8f |
files | src/dict.c src/errors.h src/evalvars.c src/list.c src/testdir/test_vim9_expr.vim src/testdir/vim9.vim src/userfunc.c src/version.c src/vim9compile.c src/vim9script.c src/vim9type.c |
diffstat | 11 files changed, 65 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dict.c +++ b/src/dict.c @@ -862,7 +862,7 @@ eval_dict(char_u **arg, typval_T *rettv, if (evaluate) { if (*skipwhite(*arg) == ':') - semsg(_(e_no_white_space_allowed_before), ":"); + semsg(_(e_no_white_space_allowed_before_str), ":"); else semsg(_(e_missing_dict_colon), *arg); } @@ -881,7 +881,7 @@ eval_dict(char_u **arg, typval_T *rettv, } if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1])) { - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); clear_tv(&tvkey); goto failret; } @@ -924,7 +924,7 @@ eval_dict(char_u **arg, typval_T *rettv, { if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1])) { - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); goto failret; } *arg = skipwhite(*arg + 1); @@ -939,7 +939,7 @@ eval_dict(char_u **arg, typval_T *rettv, if (evaluate) { if (**arg == ',') - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); else semsg(_(e_missing_dict_comma), *arg); }
--- a/src/errors.h +++ b/src/errors.h @@ -33,7 +33,7 @@ EXTERN char e_syntax_error_at_str[] INIT(= N_("E1002: Syntax error at %s")); EXTERN char e_missing_return_value[] INIT(= N_("E1003: Missing return value")); -EXTERN char e_white_space_required_before_and_after[] +EXTERN char e_white_space_required_before_and_after_str[] INIT(= N_("E1004: white space required before and after '%s'")); EXTERN char e_too_many_argument_types[] INIT(= N_("E1005: Too many argument types")); @@ -156,13 +156,13 @@ EXTERN char e_type_mismatch_for_v_variab INIT(= N_("E1063: type mismatch for v: variable")); // E1064 unused // E1065 unused -EXTERN char e_cannot_declare_a_register[] +EXTERN char e_cannot_declare_a_register_str[] INIT(= N_("E1066: Cannot declare a register: %s")); -EXTERN char e_separator_mismatch[] +EXTERN char e_separator_mismatch_str[] INIT(= N_("E1067: Separator mismatch: %s")); -EXTERN char e_no_white_space_allowed_before[] +EXTERN char e_no_white_space_allowed_before_str[] INIT(= N_("E1068: No white space allowed before '%s'")); -EXTERN char e_white_space_required_after[] +EXTERN char e_white_space_required_after_str[] INIT(= N_("E1069: white space required after '%s'")); EXTERN char e_missing_from[] INIT(= N_("E1070: Missing \"from\"")); @@ -170,7 +170,7 @@ EXTERN char e_invalid_string_after_from[ INIT(= N_("E1071: Invalid string after \"from\"")); EXTERN char e_cannot_compare_str_with_str[] INIT(= N_("E1072: Cannot compare %s with %s")); -EXTERN char e_name_already_defined[] +EXTERN char e_name_already_defined_str[] INIT(= N_("E1073: name already defined: %s")); EXTERN char e_no_white_space_allowed_after_dot[] INIT(= N_("E1074: no white space allowed after dot"));
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -811,7 +811,7 @@ ex_let(exarg_T *eap) || !IS_WHITE_OR_NUL(*expr))) { vim_strncpy(op, expr - len, len); - semsg(_(e_white_space_required_before_and_after), op); + semsg(_(e_white_space_required_before_and_after_str), op); i = FAIL; }
--- a/src/list.c +++ b/src/list.c @@ -1259,7 +1259,7 @@ eval_list(char_u **arg, typval_T *rettv, { if (vim9script && !IS_WHITE_OR_NUL((*arg)[1])) { - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); goto failret; } *arg = skipwhite(*arg + 1); @@ -1276,7 +1276,7 @@ eval_list(char_u **arg, typval_T *rettv, if (do_error) { if (**arg == ',') - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); else semsg(_("E696: Missing comma in List: %s"), *arg); }
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -2336,7 +2336,8 @@ func Test_expr_fails() call CheckDefFailure(["let x = '1'isnot2"], 'E488:', 1) call CheckDefFailure(["CallMe ('yes')"], 'E476:', 1) - call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:', 1) + call CheckScriptFailure(["CallMe ('yes')"], 'E492:', 1) + call CheckScriptAndDefFailure(["CallMe2('yes','no')"], 'E1069:', 1) call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:', 1) call CheckDefFailure(["v:nosuch += 3"], 'E1001:', 1)
--- a/src/testdir/vim9.vim +++ b/src/testdir/vim9.vim @@ -40,3 +40,10 @@ def CheckScriptSuccess(lines: list<strin so Xdef delete('Xdef') enddef + +" Check that a command fails both when used in a :def function and when used +" in Vim9 script. +def CheckScriptAndDefFailure(lines: list<string>, error: string, lnum = -3) + CheckDefFailure(lines, error, lnum) + CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) +enddef
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -119,7 +119,7 @@ one_function_arg(char_u *arg, garray_T * ++p; if (!VIM_ISWHITE(*p)) { - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); return arg; } type = skipwhite(p); @@ -276,7 +276,7 @@ get_function_args( if (!skip && in_vim9script() && !IS_WHITE_OR_NUL(*p) && *p != endchar) { - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); goto err_ret; } } @@ -623,6 +623,7 @@ get_func_tv( int ret = OK; typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments int argcount = 0; // number of arguments found + int vim9script = in_vim9script(); /* * Get the arguments. @@ -644,10 +645,25 @@ get_func_tv( ++argcount; // The comma should come right after the argument, but this wasn't // checked previously, thus only enforce it in Vim9 script. - if (!in_vim9script()) + if (vim9script) + { + if (*argp != ',' && *skipwhite(argp) == ',') + { + semsg(_(e_no_white_space_allowed_before_str), ","); + ret = FAIL; + break; + } + } + else argp = skipwhite(argp); if (*argp != ',') break; + if (vim9script && !IS_WHITE_OR_NUL(argp[1])) + { + semsg(_(e_white_space_required_after_str), ","); + ret = FAIL; + break; + } } argp = skipwhite_and_linebreak(argp, evalarg); if (*argp == ')') @@ -3275,7 +3291,7 @@ def_function(exarg_T *eap, char_u *name_ || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq))) { if (vim9script) - emsg_funcname(e_name_already_defined, name); + emsg_funcname(e_name_already_defined_str, name); else emsg_funcname(e_funcexts, name); goto erret;
--- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1504, +/**/ 1503, /**/ 1502,
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -295,7 +295,7 @@ check_defined(char_u *p, size_t len, cct || find_func_even_dead(p, FALSE, cctx) != NULL) { p[len] = c; - semsg(_(e_name_already_defined), p); + semsg(_(e_name_already_defined_str), p); return FAIL; } p[len] = c; @@ -2202,14 +2202,14 @@ compile_arguments(char_u **arg, cctx_T * if (*p != ',' && *skipwhite(p) == ',') { - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); p = skipwhite(p); } if (*p == ',') { ++p; if (*p != NUL && !VIM_ISWHITE(*p)) - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); } whitep = p; p = skipwhite(p); @@ -2416,7 +2416,7 @@ compile_list(char_u **arg, cctx_T *cctx) } if (*p == ',') { - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); return FAIL; } if (*p == ']') @@ -2432,7 +2432,7 @@ compile_list(char_u **arg, cctx_T *cctx) ++p; if (*p != ']' && !IS_WHITE_OR_NUL(*p)) { - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); return FAIL; } } @@ -2618,7 +2618,7 @@ compile_dict(char_u **arg, cctx_T *cctx, if (**arg != ':') { if (*skipwhite(*arg) == ':') - semsg(_(e_no_white_space_allowed_before), ":"); + semsg(_(e_no_white_space_allowed_before_str), ":"); else semsg(_(e_missing_dict_colon), *arg); return FAIL; @@ -2626,7 +2626,7 @@ compile_dict(char_u **arg, cctx_T *cctx, whitep = *arg + 1; if (!IS_WHITE_OR_NUL(*whitep)) { - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); return FAIL; } @@ -2657,7 +2657,7 @@ compile_dict(char_u **arg, cctx_T *cctx, } if (IS_WHITE_OR_NUL(*whitep)) { - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); return FAIL; } whitep = *arg + 1; @@ -3518,7 +3518,7 @@ error_white_both(char_u *op, int len) char_u buf[10]; vim_strncpy(buf, op, len); - semsg(_(e_white_space_required_before_and_after), buf); + semsg(_(e_white_space_required_before_and_after_str), buf); } /* @@ -3542,7 +3542,7 @@ compile_expr7t(char_u **arg, cctx_T *cct if (**arg != '>') { if (*skipwhite(*arg) == '>') - semsg(_(e_no_white_space_allowed_before), ">"); + semsg(_(e_no_white_space_allowed_before_str), ">"); else emsg(_(e_missing_gt)); return FAIL; @@ -3887,7 +3887,7 @@ compile_and_or( if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2])) { - semsg(_(e_white_space_required_before_and_after), op); + semsg(_(e_white_space_required_before_and_after_str), op); return FAIL; } @@ -4028,7 +4028,7 @@ compile_expr1(char_u **arg, cctx_T *cct if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) { - semsg(_(e_white_space_required_before_and_after), "?"); + semsg(_(e_white_space_required_before_and_after_str), "?"); return FAIL; } @@ -4087,7 +4087,7 @@ compile_expr1(char_u **arg, cctx_T *cct if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) { - semsg(_(e_white_space_required_before_and_after), ":"); + semsg(_(e_white_space_required_before_and_after_str), ":"); return FAIL; } @@ -4394,7 +4394,7 @@ vim9_declare_error(char_u *name) return; case '&': semsg(_(e_cannot_declare_an_option), name); return; - case '@': semsg(_(e_cannot_declare_a_register), name); + case '@': semsg(_(e_cannot_declare_a_register_str), name); return; default: return; } @@ -4775,7 +4775,7 @@ compile_assignment(char_u *arg, exarg_T // parse optional type: "let var: type = expr" if (!VIM_ISWHITE(p[1])) { - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); goto theend; } p = skipwhite(p + 1); @@ -6042,7 +6042,7 @@ compile_catch(char_u *arg, cctx_T *cctx end = skip_regexp_ex(p + 1, *p, TRUE, &tofree, &dropped); if (*end != *p) { - semsg(_(e_separator_mismatch), p); + semsg(_(e_separator_mismatch_str), p); vim_free(tofree); return FAIL; }
--- a/src/vim9script.c +++ b/src/vim9script.c @@ -532,7 +532,7 @@ vim9_declare_scriptvar(exarg_T *eap, cha } if (!VIM_ISWHITE(p[1])) { - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); return arg + STRLEN(arg); } name = vim_strnsave(arg, p - arg);
--- a/src/vim9type.c +++ b/src/vim9type.c @@ -471,7 +471,7 @@ parse_type_member(char_u **arg, type_T * if (**arg != '<') { if (*skipwhite(*arg) == '<') - semsg(_(e_no_white_space_allowed_before), "<"); + semsg(_(e_no_white_space_allowed_before_str), "<"); else emsg(_(e_missing_type)); return type; @@ -600,7 +600,7 @@ parse_type(char_u **arg, garray_T *type_ if (*p != ',' && *skipwhite(p) == ',') { - semsg(_(e_no_white_space_allowed_before), ","); + semsg(_(e_no_white_space_allowed_before_str), ","); return &t_any; } if (*p == ',') @@ -608,7 +608,7 @@ parse_type(char_u **arg, garray_T *type_ ++p; if (!VIM_ISWHITE(*p)) { - semsg(_(e_white_space_required_after), ","); + semsg(_(e_white_space_required_after_str), ","); return &t_any; } } @@ -633,7 +633,7 @@ parse_type(char_u **arg, garray_T *type_ // parse return type ++*arg; if (!VIM_ISWHITE(**arg)) - semsg(_(e_white_space_required_after), ":"); + semsg(_(e_white_space_required_after_str), ":"); *arg = skipwhite(*arg); ret_type = parse_type(arg, type_gap); }