To: vim_dev@googlegroups.com Subject: Patch 9.0.0229 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0229 Problem: Vim9: error message for missing type is not clear. Solution: Mention the context. (issue #10944) Files: src/vim9type.c, src/errors.h, src/testdir/test_vim9_func.vim, src/testdir/test_vim9_assign.vim *** ../vim-9.0.0228/src/vim9type.c 2022-05-26 22:21:46.000000000 +0100 --- src/vim9type.c 2022-08-20 11:50:55.516311451 +0100 *************** *** 879,884 **** --- 879,885 ---- /* * Parse the member type: "" and return "type" with the member set. * Use "type_gap" if a new type needs to be added. + * "info" is extra information for an error message. * Returns NULL in case of failure. */ static type_T * *************** *** 886,893 **** char_u **arg, type_T *type, garray_T *type_gap, ! int give_error) { type_T *member_type; int prev_called_emsg = called_emsg; --- 887,896 ---- char_u **arg, type_T *type, garray_T *type_gap, ! int give_error, ! char *info) { + char_u *arg_start = *arg; type_T *member_type; int prev_called_emsg = called_emsg; *************** *** 898,904 **** if (*skipwhite(*arg) == '<') semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg); else ! emsg(_(e_missing_type)); } return NULL; } --- 901,907 ---- if (*skipwhite(*arg) == '<') semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg); else ! semsg(_(e_missing_type_after_str), info); } return NULL; } *************** *** 912,918 **** if (**arg != '>' && called_emsg == prev_called_emsg) { if (give_error) ! emsg(_(e_missing_gt_after_type)); return NULL; } ++*arg; --- 915,921 ---- if (**arg != '>' && called_emsg == prev_called_emsg) { if (give_error) ! semsg(_(e_missing_gt_after_type_str), arg_start); return NULL; } ++*arg; *************** *** 971,977 **** { *arg += len; return parse_type_member(arg, &t_dict_any, ! type_gap, give_error); } break; case 'f': --- 974,980 ---- { *arg += len; return parse_type_member(arg, &t_dict_any, ! type_gap, give_error, "dict"); } break; case 'f': *************** *** 1115,1121 **** { *arg += len; return parse_type_member(arg, &t_list_any, ! type_gap, give_error); } break; case 'n': --- 1118,1124 ---- { *arg += len; return parse_type_member(arg, &t_list_any, ! type_gap, give_error, "list"); } break; case 'n': *** ../vim-9.0.0228/src/errors.h 2022-08-10 19:50:44.117894641 +0100 --- src/errors.h 2022-08-20 11:49:48.440361065 +0100 *************** *** 2634,2643 **** INIT(= N_("E1006: %s is used as an argument")); EXTERN char e_mandatory_argument_after_optional_argument[] INIT(= N_("E1007: Mandatory argument after optional argument")); ! EXTERN char e_missing_type[] ! INIT(= N_("E1008: Missing ")); ! EXTERN char e_missing_gt_after_type[] ! INIT(= N_("E1009: Missing > after type")); EXTERN char e_type_not_recognized_str[] INIT(= N_("E1010: Type not recognized: %s")); EXTERN char e_name_too_long_str[] --- 2634,2643 ---- INIT(= N_("E1006: %s is used as an argument")); EXTERN char e_mandatory_argument_after_optional_argument[] INIT(= N_("E1007: Mandatory argument after optional argument")); ! EXTERN char e_missing_type_after_str[] ! INIT(= N_("E1008: Missing after %s")); ! EXTERN char e_missing_gt_after_type_str[] ! INIT(= N_("E1009: Missing > after type: %s")); EXTERN char e_type_not_recognized_str[] INIT(= N_("E1010: Type not recognized: %s")); EXTERN char e_name_too_long_str[] *** ../vim-9.0.0228/src/testdir/test_vim9_func.vim 2022-08-16 19:34:40.863551410 +0100 --- src/testdir/test_vim9_func.vim 2022-08-20 11:56:02.209399276 +0100 *************** *** 2164,2172 **** 'defcompile'], 'E1059:') delfunc! g:Func ! v9.CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') delfunc! g:Func ! v9.CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') delfunc! g:Func v9.CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') delfunc! g:Func --- 2164,2172 ---- 'defcompile'], 'E1059:') delfunc! g:Func ! v9.CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008: Missing after list') delfunc! g:Func ! v9.CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008: Missing after dict') delfunc! g:Func v9.CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') delfunc! g:Func *************** *** 2183,2189 **** enddef def Test_arg_type_wrong() ! v9.CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing ') v9.CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...') v9.CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:') v9.CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:') --- 2183,2189 ---- enddef def Test_arg_type_wrong() ! v9.CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing after list') v9.CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...') v9.CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:') v9.CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:') *** ../vim-9.0.0228/src/testdir/test_vim9_assign.vim 2022-05-26 22:17:30.000000000 +0100 --- src/testdir/test_vim9_assign.vim 2022-08-20 11:56:53.337036350 +0100 *************** *** 1591,1597 **** v9.CheckDefFailure(['var name: number = feedkeys("0")'], 'expected number but got void') v9.CheckDefFailure(['var name: dict '], 'E1068:') ! v9.CheckDefFailure(['var name: dict'], 'E1068:') ! v9.CheckDefFailure(['var name: dict after type: