@@ -314,6 +314,11 @@ get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
314314 // recognize commonly used types
315315 if (argcount <= 0 )
316316 {
317+ if (ret_type == & t_unknown )
318+ {
319+ // (argcount == 0) is not possible
320+ return & t_func_unknown ;
321+ }
317322 if (ret_type == & t_void )
318323 {
319324 if (argcount == 0 )
@@ -350,6 +355,7 @@ get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
350355 return & t_any ;
351356 type -> tt_type = VAR_FUNC ;
352357 type -> tt_member = ret_type ;
358+ type -> tt_argcount = argcount ;
353359 type -> tt_args = NULL ;
354360 return type ;
355361}
@@ -1589,7 +1595,7 @@ parse_type(char_u **arg, garray_T *type_gap)
15891595 if (len == 4 && STRNCMP (* arg , "func" , len ) == 0 )
15901596 {
15911597 type_T * type ;
1592- type_T * ret_type = & t_any ;
1598+ type_T * ret_type = & t_unknown ;
15931599 int argcount = -1 ;
15941600 int flags = 0 ;
15951601 int first_optional = -1 ;
@@ -1657,7 +1663,7 @@ parse_type(char_u **arg, garray_T *type_gap)
16571663 {
16581664 // parse return type
16591665 ++ * arg ;
1660- if (!VIM_ISWHITE (* p ))
1666+ if (!VIM_ISWHITE (* * arg ))
16611667 semsg (_ (e_white_after ), ":" );
16621668 * arg = skipwhite (* arg );
16631669 ret_type = parse_type (arg , type_gap );
@@ -2405,7 +2411,10 @@ check_type(type_T *expected, type_T *actual, int give_msg)
24052411{
24062412 int ret = OK ;
24072413
2408- if (expected -> tt_type != VAR_UNKNOWN && expected -> tt_type != VAR_ANY )
2414+ // When expected is "unknown" we accept any actual type.
2415+ // When expected is "any" we accept any actual type except "void".
2416+ if (expected -> tt_type != VAR_UNKNOWN
2417+ && (expected -> tt_type != VAR_ANY || actual -> tt_type == VAR_VOID ))
24092418 {
24102419 if (expected -> tt_type != actual -> tt_type )
24112420 {
@@ -2421,8 +2430,7 @@ check_type(type_T *expected, type_T *actual, int give_msg)
24212430 }
24222431 else if (expected -> tt_type == VAR_FUNC )
24232432 {
2424- if (expected -> tt_member != & t_any
2425- && expected -> tt_member != & t_unknown )
2433+ if (expected -> tt_member != & t_unknown )
24262434 ret = check_type (expected -> tt_member , actual -> tt_member , FALSE);
24272435 if (ret == OK && expected -> tt_argcount != -1
24282436 && (actual -> tt_argcount < expected -> tt_min_argcount
@@ -4044,36 +4052,39 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
40444052 if (r == FAIL )
40454053 goto theend ;
40464054
4047- stack = & cctx -> ctx_type_stack ;
4048- stacktype = stack -> ga_len == 0 ? & t_void
4049- : ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
4050- if (idx >= 0 && (is_decl || !has_type ))
4055+ if (cctx -> ctx_skip != TRUE)
40514056 {
4052- lvar = ((lvar_T * )cctx -> ctx_locals .ga_data ) + idx ;
4053- if (new_local && !has_type )
4057+ stack = & cctx -> ctx_type_stack ;
4058+ stacktype = stack -> ga_len == 0 ? & t_void
4059+ : ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
4060+ if (idx >= 0 && (is_decl || !has_type ))
40544061 {
4055- if (stacktype -> tt_type == VAR_VOID )
4056- {
4057- emsg (_ ("E1031: Cannot use void value" ));
4058- goto theend ;
4059- }
4060- else
4062+ lvar = ((lvar_T * )cctx -> ctx_locals .ga_data ) + idx ;
4063+ if (new_local && !has_type )
40614064 {
4062- // An empty list or dict has a &t_void member, for a
4063- // variable that implies &t_any.
4064- if (stacktype == & t_list_empty )
4065- lvar -> lv_type = & t_list_any ;
4066- else if (stacktype == & t_dict_empty )
4067- lvar -> lv_type = & t_dict_any ;
4065+ if (stacktype -> tt_type == VAR_VOID )
4066+ {
4067+ emsg (_ ("E1031: Cannot use void value" ));
4068+ goto theend ;
4069+ }
40684070 else
4069- lvar -> lv_type = stacktype ;
4071+ {
4072+ // An empty list or dict has a &t_void member, for a
4073+ // variable that implies &t_any.
4074+ if (stacktype == & t_list_empty )
4075+ lvar -> lv_type = & t_list_any ;
4076+ else if (stacktype == & t_dict_empty )
4077+ lvar -> lv_type = & t_dict_any ;
4078+ else
4079+ lvar -> lv_type = stacktype ;
4080+ }
40704081 }
4082+ else if (need_type (stacktype , lvar -> lv_type , -1 , cctx ) == FAIL )
4083+ goto theend ;
40714084 }
4072- else if (need_type ( stacktype , lvar -> lv_type , -1 , cctx ) == FAIL )
4085+ else if (* p != '=' && check_type ( type , stacktype , TRUE ) == FAIL )
40734086 goto theend ;
40744087 }
4075- else if (* p != '=' && check_type (type , stacktype , TRUE) == FAIL )
4076- goto theend ;
40774088 }
40784089 else if (cmdidx == CMD_const )
40794090 {
0 commit comments