@@ -878,11 +878,12 @@ use_typecheck(type_T *actual, type_T *expected)
878878 * If "actual_is_const" is TRUE then the type won't change at runtime, do not
879879 * generate a TYPECHECK.
880880 */
881- static int
881+ int
882882need_type (
883883 type_T * actual ,
884884 type_T * expected ,
885885 int offset ,
886+ int arg_idx ,
886887 cctx_T * cctx ,
887888 int silent ,
888889 int actual_is_const )
@@ -896,7 +897,7 @@ need_type(
896897 return OK ;
897898 }
898899
899- if (check_type (expected , actual , FALSE, 0 ) == OK )
900+ if (check_type (expected , actual , FALSE, arg_idx ) == OK )
900901 return OK ;
901902
902903 // If the actual type can be the expected type add a runtime check.
@@ -908,7 +909,7 @@ need_type(
908909 }
909910
910911 if (!silent )
911- type_mismatch (expected , actual );
912+ arg_type_mismatch (expected , actual , arg_idx );
912913 return FAIL ;
913914}
914915
@@ -931,7 +932,7 @@ bool_on_stack(cctx_T *cctx)
931932 // This requires a runtime type check.
932933 return generate_COND2BOOL (cctx );
933934
934- return need_type (type , & t_bool , -1 , cctx , FALSE, FALSE);
935+ return need_type (type , & t_bool , -1 , 0 , cctx , FALSE, FALSE);
935936}
936937
937938/*
@@ -1613,7 +1614,8 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
16131614 {
16141615 // Check the types of the arguments.
16151616 argtypes = ((type_T * * )stack -> ga_data ) + stack -> ga_len - argcount ;
1616- if (internal_func_check_arg_types (argtypes , func_idx , argcount ) == FAIL )
1617+ if (internal_func_check_arg_types (argtypes , func_idx , argcount ,
1618+ cctx ) == FAIL )
16171619 return FAIL ;
16181620 if (internal_func_is_map (func_idx ))
16191621 maptype = * argtypes ;
@@ -1656,7 +1658,7 @@ generate_LISTAPPEND(cctx_T *cctx)
16561658 list_type = ((type_T * * )stack -> ga_data )[stack -> ga_len - 2 ];
16571659 item_type = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
16581660 expected = list_type -> tt_member ;
1659- if (need_type (item_type , expected , -1 , cctx , FALSE, FALSE) == FAIL )
1661+ if (need_type (item_type , expected , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
16601662 return FAIL ;
16611663
16621664 if (generate_instr (cctx , ISN_LISTAPPEND ) == NULL )
@@ -1678,7 +1680,7 @@ generate_BLOBAPPEND(cctx_T *cctx)
16781680
16791681 // Caller already checked that blob_type is a blob.
16801682 item_type = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
1681- if (need_type (item_type , & t_number , -1 , cctx , FALSE, FALSE) == FAIL )
1683+ if (need_type (item_type , & t_number , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
16821684 return FAIL ;
16831685
16841686 if (generate_instr (cctx , ISN_BLOBAPPEND ) == NULL )
@@ -1733,7 +1735,7 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
17331735 else
17341736 expected = ufunc -> uf_va_type -> tt_member ;
17351737 actual = ((type_T * * )stack -> ga_data )[stack -> ga_len - argcount + i ];
1736- if (need_type (actual , expected , - argcount + i , cctx ,
1738+ if (need_type (actual , expected , - argcount + i , 0 , cctx ,
17371739 TRUE, FALSE) == FAIL )
17381740 {
17391741 arg_type_mismatch (expected , actual , i + 1 );
@@ -1850,7 +1852,7 @@ generate_PCALL(
18501852 type -> tt_argcount - 1 ]-> tt_member ;
18511853 else
18521854 expected = type -> tt_args [i ];
1853- if (need_type (actual , expected , offset ,
1855+ if (need_type (actual , expected , offset , 0 ,
18541856 cctx , TRUE, FALSE) == FAIL )
18551857 {
18561858 arg_type_mismatch (expected , actual , i + 1 );
@@ -3135,7 +3137,7 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
31353137 {
31363138 type_T * keytype = ((type_T * * )stack -> ga_data )
31373139 [stack -> ga_len - 1 ];
3138- if (need_type (keytype , & t_string , -1 , cctx ,
3140+ if (need_type (keytype , & t_string , -1 , 0 , cctx ,
31393141 FALSE, FALSE) == FAIL )
31403142 return FAIL ;
31413143 }
@@ -3808,13 +3810,13 @@ compile_subscript(
38083810 vtype = VAR_DICT ;
38093811 if (vtype == VAR_STRING || vtype == VAR_LIST || vtype == VAR_BLOB )
38103812 {
3811- if (need_type (valtype , & t_number , -1 , cctx ,
3813+ if (need_type (valtype , & t_number , -1 , 0 , cctx ,
38123814 FALSE, FALSE) == FAIL )
38133815 return FAIL ;
38143816 if (is_slice )
38153817 {
38163818 valtype = ((type_T * * )stack -> ga_data )[stack -> ga_len - 2 ];
3817- if (need_type (valtype , & t_number , -2 , cctx ,
3819+ if (need_type (valtype , & t_number , -2 , 0 , cctx ,
38183820 FALSE, FALSE) == FAIL )
38193821 return FAIL ;
38203822 }
@@ -3836,7 +3838,7 @@ compile_subscript(
38363838 }
38373839 else
38383840 {
3839- if (need_type (* typep , & t_dict_any , -2 , cctx ,
3841+ if (need_type (* typep , & t_dict_any , -2 , 0 , cctx ,
38403842 FALSE, FALSE) == FAIL )
38413843 return FAIL ;
38423844 * typep = & t_any ;
@@ -4235,7 +4237,7 @@ compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
42354237 actual = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
42364238 if (check_type (want_type , actual , FALSE, 0 ) == FAIL )
42374239 {
4238- if (need_type (actual , want_type , -1 , cctx , FALSE, FALSE) == FAIL )
4240+ if (need_type (actual , want_type , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
42394241 return FAIL ;
42404242 }
42414243 }
@@ -4917,7 +4919,7 @@ compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
49174919 return NULL ;
49184920 }
49194921 if (need_type (stack_type , cctx -> ctx_ufunc -> uf_ret_type , -1 ,
4920- cctx , FALSE, FALSE) == FAIL )
4922+ 0 , cctx , FALSE, FALSE) == FAIL )
49214923 return NULL ;
49224924 }
49234925 }
@@ -5831,7 +5833,7 @@ compile_assign_unlet(
58315833 : ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
58325834 // now we can properly check the type
58335835 if (lhs -> lhs_type -> tt_member != NULL && rhs_type != & t_void
5834- && need_type (rhs_type , lhs -> lhs_type -> tt_member , -2 , cctx ,
5836+ && need_type (rhs_type , lhs -> lhs_type -> tt_member , -2 , 0 , cctx ,
58355837 FALSE, FALSE) == FAIL )
58365838 return FAIL ;
58375839 }
@@ -5976,7 +5978,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
59765978 emsg (_ (e_cannot_use_void_value ));
59775979 goto theend ;
59785980 }
5979- if (need_type (stacktype , & t_list_any , -1 , cctx ,
5981+ if (need_type (stacktype , & t_list_any , -1 , 0 , cctx ,
59805982 FALSE, FALSE) == FAIL )
59815983 goto theend ;
59825984 // TODO: check the length of a constant list here
@@ -6123,13 +6125,13 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
61236125 // without operator check type here, otherwise below
61246126 if (lhs .lhs_has_index )
61256127 use_type = lhs .lhs_member_type ;
6126- if (need_type (rhs_type , use_type , -1 , cctx ,
6128+ if (need_type (rhs_type , use_type , -1 , 0 , cctx ,
61276129 FALSE, is_const ) == FAIL )
61286130 goto theend ;
61296131 }
61306132 }
61316133 else if (* p != '=' && need_type (rhs_type , lhs .lhs_member_type ,
6132- -1 , cctx , FALSE, FALSE) == FAIL )
6134+ -1 , 0 , cctx , FALSE, FALSE) == FAIL )
61336135 goto theend ;
61346136 }
61356137 else if (cmdidx == CMD_final )
@@ -6216,7 +6218,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
62166218 // If variable is float operation with number is OK.
62176219 !(expected == & t_float && stacktype == & t_number ) &&
62186220#endif
6219- need_type (stacktype , expected , -1 , cctx ,
6221+ need_type (stacktype , expected , -1 , 0 , cctx ,
62206222 FALSE, FALSE) == FAIL )
62216223 goto theend ;
62226224
@@ -6925,7 +6927,7 @@ compile_for(char_u *arg_start, cctx_T *cctx)
69256927 // Now that we know the type of "var", check that it is a list, now or at
69266928 // runtime.
69276929 vartype = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
6928- if (need_type (vartype , & t_list_any , -1 , cctx , FALSE, FALSE) == FAIL )
6930+ if (need_type (vartype , & t_list_any , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
69296931 {
69306932 drop_scope (cctx );
69316933 return NULL ;
0 commit comments