patch 8.2.1408: Vim9: type casting not supported
Problem: Vim9: type casting not supported.
Solution: Introduce type casting.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 19760fb..81206b3 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3402,6 +3402,56 @@
}
/*
+ * <type>expr7: runtime type check / conversion
+ */
+ static int
+compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
+{
+ type_T *want_type = NULL;
+
+ // Recognize <type>
+ if (**arg == '<' && eval_isnamec1((*arg)[1]))
+ {
+ int called_emsg_before = called_emsg;
+
+ ++*arg;
+ want_type = parse_type(arg, cctx->ctx_type_list);
+ if (called_emsg != called_emsg_before)
+ return FAIL;
+
+ if (**arg != '>')
+ {
+ if (*skipwhite(*arg) == '>')
+ semsg(_(e_no_white_before), ">");
+ else
+ emsg(_("E1104: Missing >"));
+ return FAIL;
+ }
+ ++*arg;
+ if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL)
+ return FAIL;
+ }
+
+ if (compile_expr7(arg, cctx, ppconst) == FAIL)
+ return FAIL;
+
+ if (want_type != NULL)
+ {
+ garray_T *stack = &cctx->ctx_type_stack;
+ type_T *actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
+
+ if (check_type(want_type, actual, FALSE) == FAIL)
+ {
+ generate_ppconst(cctx, ppconst);
+ if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
+ return FAIL;
+ }
+ }
+
+ return OK;
+}
+
+/*
* * number multiplication
* / number division
* % number modulo
@@ -3414,7 +3464,7 @@
int ppconst_used = ppconst->pp_used;
// get the first expression
- if (compile_expr7(arg, cctx, ppconst) == FAIL)
+ if (compile_expr7t(arg, cctx, ppconst) == FAIL)
return FAIL;
/*
@@ -3441,7 +3491,7 @@
return FAIL;
// get the second expression
- if (compile_expr7(arg, cctx, ppconst) == FAIL)
+ if (compile_expr7t(arg, cctx, ppconst) == FAIL)
return FAIL;
if (ppconst->pp_used == ppconst_used + 2