patch 8.2.1183: assert_fails() checks the last error message
Problem: assert_fails() checks the last error message.
Solution: Check the first error, it is more relevant. Fix all the tests
that rely on the old behavior.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8905ee3..fceb481 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -912,7 +912,12 @@
* - return FAIL.
*/
static int
-need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx)
+need_type(
+ type_T *actual,
+ type_T *expected,
+ int offset,
+ cctx_T *cctx,
+ int silent)
{
if (check_type(expected, actual, FALSE) == OK)
return OK;
@@ -921,7 +926,8 @@
&& !(actual->tt_type == VAR_FUNC
&& (actual->tt_member == &t_any || actual->tt_argcount < 0)))
{
- type_mismatch(expected, actual);
+ if (!silent)
+ type_mismatch(expected, actual);
return FAIL;
}
generate_TYPECHECK(cctx, expected, offset);
@@ -1538,7 +1544,7 @@
else
expected = ufunc->uf_va_type->tt_member;
actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
- if (need_type(actual, expected, -argcount + i, cctx) == FAIL)
+ if (need_type(actual, expected, -argcount + i, cctx, TRUE) == FAIL)
{
arg_type_mismatch(expected, actual, i + 1);
return FAIL;
@@ -4640,8 +4646,8 @@
emsg(_("E1096: Returning a value in a function without a return type"));
return NULL;
}
- if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, cctx)
- == FAIL)
+ if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
+ cctx, FALSE) == FAIL)
return NULL;
}
}
@@ -4942,7 +4948,7 @@
emsg(_(e_cannot_use_void));
goto theend;
}
- if (need_type(stacktype, &t_list_any, -1, cctx) == FAIL)
+ if (need_type(stacktype, &t_list_any, -1, cctx, FALSE) == FAIL)
goto theend;
generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count,
semicolon);
@@ -5356,13 +5362,13 @@
if (use_type == NULL)
use_type = &t_void;
}
- if (need_type(stacktype, use_type, -1, cctx)
+ if (need_type(stacktype, use_type, -1, cctx, FALSE)
== FAIL)
goto theend;
}
}
else if (*p != '=' && need_type(stacktype, member_type, -1,
- cctx) == FAIL)
+ cctx, FALSE) == FAIL)
goto theend;
}
else if (cmdidx == CMD_const)
@@ -5439,7 +5445,7 @@
if (*op == '.')
expected = &t_string;
stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
- if (need_type(stacktype, expected, -1, cctx) == FAIL)
+ if (need_type(stacktype, expected, -1, cctx, FALSE) == FAIL)
goto theend;
if (*op == '.')
@@ -6128,7 +6134,7 @@
// Now that we know the type of "var", check that it is a list, now or at
// runtime.
vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
- if (need_type(vartype, &t_list_any, -1, cctx) == FAIL)
+ if (need_type(vartype, &t_list_any, -1, cctx, FALSE) == FAIL)
{
drop_scope(cctx);
return NULL;