Mercurial > vim
comparison src/vim9compile.c @ 21265:6a4806e326dd v8.2.1183
patch 8.2.1183: assert_fails() checks the last error message
Commit: https://github.com/vim/vim/commit/9b7bf9e98f06ece595fed7a3ff53ecce89797a53
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 11 22:14:59 2020 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 Jul 2020 22:30:07 +0200 |
parents | 4be91a7eafb2 |
children | 13b1567ae0c6 |
comparison
equal
deleted
inserted
replaced
21264:f3bdfe1d9359 | 21265:6a4806e326dd |
---|---|
910 * - "actual" is "expected" type or | 910 * - "actual" is "expected" type or |
911 * - "actual" is a type that can be "expected" type: add a runtime check; or | 911 * - "actual" is a type that can be "expected" type: add a runtime check; or |
912 * - return FAIL. | 912 * - return FAIL. |
913 */ | 913 */ |
914 static int | 914 static int |
915 need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx) | 915 need_type( |
916 type_T *actual, | |
917 type_T *expected, | |
918 int offset, | |
919 cctx_T *cctx, | |
920 int silent) | |
916 { | 921 { |
917 if (check_type(expected, actual, FALSE) == OK) | 922 if (check_type(expected, actual, FALSE) == OK) |
918 return OK; | 923 return OK; |
919 if (actual->tt_type != VAR_ANY | 924 if (actual->tt_type != VAR_ANY |
920 && actual->tt_type != VAR_UNKNOWN | 925 && actual->tt_type != VAR_UNKNOWN |
921 && !(actual->tt_type == VAR_FUNC | 926 && !(actual->tt_type == VAR_FUNC |
922 && (actual->tt_member == &t_any || actual->tt_argcount < 0))) | 927 && (actual->tt_member == &t_any || actual->tt_argcount < 0))) |
923 { | 928 { |
924 type_mismatch(expected, actual); | 929 if (!silent) |
930 type_mismatch(expected, actual); | |
925 return FAIL; | 931 return FAIL; |
926 } | 932 } |
927 generate_TYPECHECK(cctx, expected, offset); | 933 generate_TYPECHECK(cctx, expected, offset); |
928 return OK; | 934 return OK; |
929 } | 935 } |
1536 expected = ufunc->uf_arg_types[i]; | 1542 expected = ufunc->uf_arg_types[i]; |
1537 } | 1543 } |
1538 else | 1544 else |
1539 expected = ufunc->uf_va_type->tt_member; | 1545 expected = ufunc->uf_va_type->tt_member; |
1540 actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i]; | 1546 actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i]; |
1541 if (need_type(actual, expected, -argcount + i, cctx) == FAIL) | 1547 if (need_type(actual, expected, -argcount + i, cctx, TRUE) == FAIL) |
1542 { | 1548 { |
1543 arg_type_mismatch(expected, actual, i + 1); | 1549 arg_type_mismatch(expected, actual, i + 1); |
1544 return FAIL; | 1550 return FAIL; |
1545 } | 1551 } |
1546 } | 1552 } |
4638 && stack_type->tt_type != VAR_UNKNOWN) | 4644 && stack_type->tt_type != VAR_UNKNOWN) |
4639 { | 4645 { |
4640 emsg(_("E1096: Returning a value in a function without a return type")); | 4646 emsg(_("E1096: Returning a value in a function without a return type")); |
4641 return NULL; | 4647 return NULL; |
4642 } | 4648 } |
4643 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, cctx) | 4649 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, |
4644 == FAIL) | 4650 cctx, FALSE) == FAIL) |
4645 return NULL; | 4651 return NULL; |
4646 } | 4652 } |
4647 } | 4653 } |
4648 else | 4654 else |
4649 { | 4655 { |
4940 if (stacktype->tt_type == VAR_VOID) | 4946 if (stacktype->tt_type == VAR_VOID) |
4941 { | 4947 { |
4942 emsg(_(e_cannot_use_void)); | 4948 emsg(_(e_cannot_use_void)); |
4943 goto theend; | 4949 goto theend; |
4944 } | 4950 } |
4945 if (need_type(stacktype, &t_list_any, -1, cctx) == FAIL) | 4951 if (need_type(stacktype, &t_list_any, -1, cctx, FALSE) == FAIL) |
4946 goto theend; | 4952 goto theend; |
4947 generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count, | 4953 generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count, |
4948 semicolon); | 4954 semicolon); |
4949 } | 4955 } |
4950 } | 4956 } |
5354 { | 5360 { |
5355 use_type = use_type->tt_member; | 5361 use_type = use_type->tt_member; |
5356 if (use_type == NULL) | 5362 if (use_type == NULL) |
5357 use_type = &t_void; | 5363 use_type = &t_void; |
5358 } | 5364 } |
5359 if (need_type(stacktype, use_type, -1, cctx) | 5365 if (need_type(stacktype, use_type, -1, cctx, FALSE) |
5360 == FAIL) | 5366 == FAIL) |
5361 goto theend; | 5367 goto theend; |
5362 } | 5368 } |
5363 } | 5369 } |
5364 else if (*p != '=' && need_type(stacktype, member_type, -1, | 5370 else if (*p != '=' && need_type(stacktype, member_type, -1, |
5365 cctx) == FAIL) | 5371 cctx, FALSE) == FAIL) |
5366 goto theend; | 5372 goto theend; |
5367 } | 5373 } |
5368 else if (cmdidx == CMD_const) | 5374 else if (cmdidx == CMD_const) |
5369 { | 5375 { |
5370 emsg(_(e_const_req_value)); | 5376 emsg(_(e_const_req_value)); |
5437 // TODO: if type is known use float or any operation | 5443 // TODO: if type is known use float or any operation |
5438 | 5444 |
5439 if (*op == '.') | 5445 if (*op == '.') |
5440 expected = &t_string; | 5446 expected = &t_string; |
5441 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; | 5447 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
5442 if (need_type(stacktype, expected, -1, cctx) == FAIL) | 5448 if (need_type(stacktype, expected, -1, cctx, FALSE) == FAIL) |
5443 goto theend; | 5449 goto theend; |
5444 | 5450 |
5445 if (*op == '.') | 5451 if (*op == '.') |
5446 generate_instr_drop(cctx, ISN_CONCAT, 1); | 5452 generate_instr_drop(cctx, ISN_CONCAT, 1); |
5447 else | 5453 else |
6126 } | 6132 } |
6127 | 6133 |
6128 // Now that we know the type of "var", check that it is a list, now or at | 6134 // Now that we know the type of "var", check that it is a list, now or at |
6129 // runtime. | 6135 // runtime. |
6130 vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; | 6136 vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
6131 if (need_type(vartype, &t_list_any, -1, cctx) == FAIL) | 6137 if (need_type(vartype, &t_list_any, -1, cctx, FALSE) == FAIL) |
6132 { | 6138 { |
6133 drop_scope(cctx); | 6139 drop_scope(cctx); |
6134 return NULL; | 6140 return NULL; |
6135 } | 6141 } |
6136 if (vartype->tt_type == VAR_LIST && vartype->tt_member->tt_type != VAR_ANY) | 6142 if (vartype->tt_type == VAR_LIST && vartype->tt_member->tt_type != VAR_ANY) |