@@ -130,6 +130,8 @@ static int compile_expr1(char_u **arg, cctx_T *cctx);
130130static int compile_expr2 (char_u * * arg , cctx_T * cctx );
131131static int compile_expr3 (char_u * * arg , cctx_T * cctx );
132132static void delete_def_function_contents (dfunc_T * dfunc );
133+ static void arg_type_mismatch (type_T * expected , type_T * actual , int argidx );
134+ static int check_type (type_T * expected , type_T * actual , int give_msg );
133135
134136/*
135137 * Lookup variable "name" in the local scope and return the index.
@@ -1240,6 +1242,32 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
12401242 return FAIL ;
12411243 }
12421244
1245+ if (ufunc -> uf_dfunc_idx >= 0 )
1246+ {
1247+ int i ;
1248+
1249+ for (i = 0 ; i < argcount ; ++ i )
1250+ {
1251+ type_T * expected ;
1252+ type_T * actual ;
1253+
1254+ if (i < regular_args )
1255+ {
1256+ if (ufunc -> uf_arg_types == NULL )
1257+ continue ;
1258+ expected = ufunc -> uf_arg_types [i ];
1259+ }
1260+ else
1261+ expected = ufunc -> uf_va_type -> tt_member ;
1262+ actual = ((type_T * * )stack -> ga_data )[stack -> ga_len - argcount + i ];
1263+ if (check_type (expected , actual , FALSE) == FAIL )
1264+ {
1265+ arg_type_mismatch (expected , actual , i + 1 );
1266+ return FAIL ;
1267+ }
1268+ }
1269+ }
1270+
12431271 // Turn varargs into a list.
12441272 if (ufunc -> uf_va_name != NULL )
12451273 {
@@ -2403,6 +2431,18 @@ type_mismatch(type_T *expected, type_T *actual)
24032431 vim_free (tofree2 );
24042432}
24052433
2434+ static void
2435+ arg_type_mismatch (type_T * expected , type_T * actual , int argidx )
2436+ {
2437+ char * tofree1 , * tofree2 ;
2438+
2439+ semsg (_ ("E1013: argument %d: type mismatch, expected %s but got %s" ),
2440+ argidx ,
2441+ type_name (expected , & tofree1 ), type_name (actual , & tofree2 ));
2442+ vim_free (tofree1 );
2443+ vim_free (tofree2 );
2444+ }
2445+
24062446/*
24072447 * Check if the expected and actual types match.
24082448 */
0 commit comments