@@ -3401,6 +3401,56 @@ error_white_both(char_u *op, int len)
34013401 semsg (_ (e_white_both ), buf );
34023402}
34033403
3404+ /*
3405+ * <type>expr7: runtime type check / conversion
3406+ */
3407+ static int
3408+ compile_expr7t (char_u * * arg , cctx_T * cctx , ppconst_T * ppconst )
3409+ {
3410+ type_T * want_type = NULL ;
3411+
3412+ // Recognize <type>
3413+ if (* * arg == '<' && eval_isnamec1 ((* arg )[1 ]))
3414+ {
3415+ int called_emsg_before = called_emsg ;
3416+
3417+ ++ * arg ;
3418+ want_type = parse_type (arg , cctx -> ctx_type_list );
3419+ if (called_emsg != called_emsg_before )
3420+ return FAIL ;
3421+
3422+ if (* * arg != '>' )
3423+ {
3424+ if (* skipwhite (* arg ) == '>' )
3425+ semsg (_ (e_no_white_before ), ">" );
3426+ else
3427+ emsg (_ ("E1104: Missing >" ));
3428+ return FAIL ;
3429+ }
3430+ ++ * arg ;
3431+ if (may_get_next_line_error (* arg - 1 , arg , cctx ) == FAIL )
3432+ return FAIL ;
3433+ }
3434+
3435+ if (compile_expr7 (arg , cctx , ppconst ) == FAIL )
3436+ return FAIL ;
3437+
3438+ if (want_type != NULL )
3439+ {
3440+ garray_T * stack = & cctx -> ctx_type_stack ;
3441+ type_T * actual = ((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ];
3442+
3443+ if (check_type (want_type , actual , FALSE) == FAIL )
3444+ {
3445+ generate_ppconst (cctx , ppconst );
3446+ if (need_type (actual , want_type , -1 , cctx , FALSE) == FAIL )
3447+ return FAIL ;
3448+ }
3449+ }
3450+
3451+ return OK ;
3452+ }
3453+
34043454/*
34053455 * * number multiplication
34063456 * / number division
@@ -3414,7 +3464,7 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
34143464 int ppconst_used = ppconst -> pp_used ;
34153465
34163466 // get the first expression
3417- if (compile_expr7 (arg , cctx , ppconst ) == FAIL )
3467+ if (compile_expr7t (arg , cctx , ppconst ) == FAIL )
34183468 return FAIL ;
34193469
34203470 /*
@@ -3441,7 +3491,7 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
34413491 return FAIL ;
34423492
34433493 // get the second expression
3444- if (compile_expr7 (arg , cctx , ppconst ) == FAIL )
3494+ if (compile_expr7t (arg , cctx , ppconst ) == FAIL )
34453495 return FAIL ;
34463496
34473497 if (ppconst -> pp_used == ppconst_used + 2
0 commit comments