@@ -526,12 +526,16 @@ use_typecheck(type_T *actual, type_T *expected)
526526 * - return FAIL.
527527 * If "actual_is_const" is TRUE then the type won't change at runtime, do not
528528 * generate a TYPECHECK.
529+ * If "typechk_flags" has TYPECHK_NUMBER_OK, then a number is accepted for
530+ * a float.
531+ * If "typechk_flags" has TYPECHK_TUPLE_OK, then a tuple is accepted for a
532+ * list.
529533 */
530534 int
531535need_type_where (
532536 type_T * actual ,
533537 type_T * expected ,
534- int number_ok , // expect VAR_FLOAT but VAR_NUMBER is OK
538+ int typechk_flags , // acceptable types (type check flags)
535539 int offset ,
536540 where_T where ,
537541 cctx_T * cctx ,
@@ -567,7 +571,7 @@ need_type_where(
567571 // If the actual type can be the expected type add a runtime check.
568572 if (!actual_is_const && ret == MAYBE && use_typecheck (actual , expected ))
569573 {
570- generate_TYPECHECK (cctx , expected , number_ok , offset ,
574+ generate_TYPECHECK (cctx , expected , typechk_flags , offset ,
571575 where .wt_kind == WT_VARIABLE , where .wt_index );
572576 return OK ;
573577 }
@@ -581,7 +585,7 @@ need_type_where(
581585need_type (
582586 type_T * actual ,
583587 type_T * expected ,
584- int number_ok , // when expected is float number is also OK
588+ int typechk_flags , // acceptable types (type check flags)
585589 int offset ,
586590 int arg_idx ,
587591 cctx_T * cctx ,
@@ -595,7 +599,7 @@ need_type(
595599 where .wt_index = arg_idx ;
596600 where .wt_kind = WT_ARGUMENT ;
597601 }
598- return need_type_where (actual , expected , number_ok , offset , where ,
602+ return need_type_where (actual , expected , typechk_flags , offset , where ,
599603 cctx , silent , actual_is_const );
600604}
601605
@@ -2521,7 +2525,7 @@ compile_load_lhs(
25212525 if (rhs_type != NULL && member_type != NULL
25222526 && vartype != VAR_OBJECT && vartype != VAR_CLASS
25232527 && rhs_type != & t_void
2524- && need_type (rhs_type , member_type , FALSE ,
2528+ && need_type (rhs_type , member_type , 0 ,
25252529 -3 , 0 , cctx , FALSE, FALSE) == FAIL )
25262530 return FAIL ;
25272531
@@ -2680,13 +2684,13 @@ compile_assign_unlet(
26802684 if (range )
26812685 {
26822686 type = get_type_on_stack (cctx , 1 );
2683- if (need_type (type , & t_number , FALSE ,
2687+ if (need_type (type , & t_number , 0 ,
26842688 -2 , 0 , cctx , FALSE, FALSE) == FAIL )
26852689 return FAIL ;
26862690 }
26872691 type = get_type_on_stack (cctx , 0 );
26882692 if ((dest_type != VAR_BLOB && type -> tt_type != VAR_SPECIAL )
2689- && need_type (type , & t_number , FALSE ,
2693+ && need_type (type , & t_number , 0 ,
26902694 -1 , 0 , cctx , FALSE, FALSE) == FAIL )
26912695 return FAIL ;
26922696 }
@@ -3041,7 +3045,7 @@ compile_assign_list_check_rhs_type(cctx_T *cctx, cac_T *cac)
30413045
30423046 if (need_type (stacktype ,
30433047 stacktype -> tt_type == VAR_TUPLE ? & t_tuple_any : & t_list_any ,
3044- FALSE , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
3048+ TYPECHK_TUPLE_OK , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
30453049 return FAIL ;
30463050
30473051 if (stacktype -> tt_type == VAR_TUPLE )
@@ -3280,7 +3284,7 @@ compile_assign_valid_rhs_type(
32803284 !has_list_index (cac -> cac_var_start + lhs -> lhs_varlen , cctx ))
32813285 use_type = lhs -> lhs_member_type ;
32823286
3283- if (need_type_where (rhs_type , use_type , FALSE , -1 , where , cctx , FALSE,
3287+ if (need_type_where (rhs_type , use_type , 0 , -1 , where , cctx , FALSE,
32843288 cac -> cac_is_const ) == FAIL )
32853289 return FALSE;
32863290
@@ -3342,7 +3346,7 @@ compile_assign_check_type(cctx_T *cctx, cac_T *cac)
33423346
33433347 if (* cac -> cac_nextc != '=' )
33443348 {
3345- if (need_type (rhs_type , lhs_type , FALSE , -1 , 0 , cctx , FALSE,
3349+ if (need_type (rhs_type , lhs_type , 0 , -1 , 0 , cctx , FALSE,
33463350 FALSE) == FAIL )
33473351 return FAIL ;
33483352 }
@@ -3493,7 +3497,7 @@ compile_assign_compound_op(cctx_T *cctx, cac_T *cac)
34933497 expected = lhs -> lhs_member_type ;
34943498 stacktype = get_type_on_stack (cctx , 0 );
34953499 if (expected != & t_string
3496- && need_type (stacktype , expected , FALSE , -1 , 0 , cctx ,
3500+ && need_type (stacktype , expected , 0 , -1 , 0 , cctx ,
34973501 FALSE, FALSE) == FAIL )
34983502 return FAIL ;
34993503 else if (may_generate_2STRING (-1 , TOSTRING_NONE , cctx ) == FAIL )
@@ -3511,8 +3515,8 @@ compile_assign_compound_op(cctx_T *cctx, cac_T *cac)
35113515 // If variable is float operation with number is OK.
35123516 !(expected == & t_float && (stacktype == & t_number
35133517 || stacktype == & t_number_bool ))
3514- && need_type (stacktype , expected , TRUE , -1 , 0 , cctx ,
3515- FALSE, FALSE) == FAIL )
3518+ && need_type (stacktype , expected , TYPECHK_NUMBER_OK , -1 , 0 ,
3519+ cctx , FALSE, FALSE) == FAIL )
35163520 return FAIL ;
35173521 }
35183522
@@ -3659,7 +3663,7 @@ compile_assign_process_variables(
36593663 SOURCING_LNUM = cac -> cac_start_lnum ;
36603664 if (cac -> cac_lhs .lhs_has_type
36613665 && need_type (& t_list_string , cac -> cac_lhs .lhs_type ,
3662- FALSE , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
3666+ 0 , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
36633667 return FAIL ;
36643668 }
36653669 else
@@ -4119,7 +4123,7 @@ obj_constructor_prologue(ufunc_T *ufunc, cctx_T *cctx)
41194123 where_T where = WHERE_INIT ;
41204124 where .wt_kind = WT_MEMBER ;
41214125 where .wt_func_name = (char * )m -> ocm_name .string ;
4122- if (need_type_where (type , m -> ocm_type , FALSE , -1 ,
4126+ if (need_type_where (type , m -> ocm_type , 0 , -1 ,
41234127 where , cctx , FALSE, FALSE) == FAIL )
41244128 return FAIL ;
41254129 }
@@ -4224,7 +4228,7 @@ compile_def_function_default_args(
42244228 ufunc -> uf_arg_types [arg_idx ] = val_type ;
42254229 }
42264230 else if (need_type_where (val_type , ufunc -> uf_arg_types [arg_idx ],
4227- FALSE , -1 , where , cctx , FALSE, FALSE) == FAIL )
4231+ 0 , -1 , where , cctx , FALSE, FALSE) == FAIL )
42284232 return FAIL ;
42294233
42304234 if (generate_STORE (cctx , ISN_STORE , i - count - off , NULL ) == FAIL )
0 commit comments