@@ -5548,6 +5548,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
55485548 if (ufunc -> uf_def_args .ga_len > 0 )
55495549 {
55505550 int count = ufunc -> uf_def_args .ga_len ;
5551+ int first_def_arg = ufunc -> uf_args .ga_len - count ;
55515552 int i ;
55525553 char_u * arg ;
55535554 int off = STACK_FRAME_SIZE + (ufunc -> uf_va_name != NULL ? 1 : 0 );
@@ -5561,11 +5562,30 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
55615562 goto erret ;
55625563 for (i = 0 ; i < count ; ++ i )
55635564 {
5565+ garray_T * stack = & cctx .ctx_type_stack ;
5566+ type_T * val_type ;
5567+ int arg_idx = first_def_arg + i ;
5568+
55645569 ufunc -> uf_def_arg_idx [i ] = instr -> ga_len ;
55655570 arg = ((char_u * * )(ufunc -> uf_def_args .ga_data ))[i ];
5566- if (compile_expr1 (& arg , & cctx ) == FAIL
5567- || generate_STORE (& cctx , ISN_STORE ,
5568- i - count - off , NULL ) == FAIL )
5571+ if (compile_expr1 (& arg , & cctx ) == FAIL )
5572+ goto erret ;
5573+
5574+ // If no type specified use the type of the default value.
5575+ // Otherwise check that the default value type matches the
5576+ // specified type.
5577+ val_type = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
5578+ if (ufunc -> uf_arg_types [arg_idx ] == & t_unknown )
5579+ ufunc -> uf_arg_types [arg_idx ] = val_type ;
5580+ else if (check_type (ufunc -> uf_arg_types [i ], val_type , FALSE)
5581+ == FAIL )
5582+ {
5583+ arg_type_mismatch (ufunc -> uf_arg_types [arg_idx ], val_type ,
5584+ arg_idx + 1 );
5585+ goto erret ;
5586+ }
5587+
5588+ if (generate_STORE (& cctx , ISN_STORE , i - count - off , NULL ) == FAIL )
55695589 goto erret ;
55705590 }
55715591
0 commit comments