Mercurial > vim
comparison src/vim9compile.c @ 19872:8a7bede7b138 v8.2.0492
patch 8.2.0492: Vim9: some error messages not tested
Commit: https://github.com/vim/vim/commit/a8c1770469504ae66c80bbdb03b6b31641215848
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Apr 1 21:17:24 2020 +0200
patch 8.2.0492: Vim9: some error messages not tested
Problem: Vim9: some error messages not tested.
Solution: Add more tests. Remove dead code. Fix uncovered bugs.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 01 Apr 2020 21:30:03 +0200 |
parents | 1136ec381dd2 |
children | f92435f0f449 |
comparison
equal
deleted
inserted
replaced
19871:7f8a267721e4 | 19872:8a7bede7b138 |
---|---|
273 type = ((type_T *)type_list->ga_data) + type_list->ga_len; | 273 type = ((type_T *)type_list->ga_data) + type_list->ga_len; |
274 ++type_list->ga_len; | 274 ++type_list->ga_len; |
275 type->tt_type = VAR_DICT; | 275 type->tt_type = VAR_DICT; |
276 type->tt_member = member_type; | 276 type->tt_member = member_type; |
277 return type; | 277 return type; |
278 } | |
279 | |
280 /* | |
281 * Return the type_T for a typval. Only for primitive types. | |
282 */ | |
283 static type_T * | |
284 typval2type(typval_T *tv) | |
285 { | |
286 if (tv->v_type == VAR_NUMBER) | |
287 return &t_number; | |
288 if (tv->v_type == VAR_BOOL) | |
289 return &t_bool; | |
290 if (tv->v_type == VAR_STRING) | |
291 return &t_string; | |
292 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles | |
293 return &t_list_string; | |
294 if (tv->v_type == VAR_DICT) // e.g. for v:completed_item | |
295 return &t_dict_any; | |
296 return &t_any; | |
278 } | 297 } |
279 | 298 |
280 ///////////////////////////////////////////////////////////////////// | 299 ///////////////////////////////////////////////////////////////////// |
281 // Following generate_ functions expect the caller to call ga_grow(). | 300 // Following generate_ functions expect the caller to call ga_grow(). |
282 | 301 |
1400 return get_dict_type(member_type, type_list); | 1419 return get_dict_type(member_type, type_list); |
1401 } | 1420 } |
1402 | 1421 |
1403 /* | 1422 /* |
1404 * Parse a type at "arg" and advance over it. | 1423 * Parse a type at "arg" and advance over it. |
1405 * Return NULL for failure. | 1424 * Return &t_any for failure. |
1406 */ | 1425 */ |
1407 type_T * | 1426 type_T * |
1408 parse_type(char_u **arg, garray_T *type_list) | 1427 parse_type(char_u **arg, garray_T *type_list) |
1409 { | 1428 { |
1410 char_u *p = *arg; | 1429 char_u *p = *arg; |
3460 assign_dest_T dest = dest_local; | 3479 assign_dest_T dest = dest_local; |
3461 int opt_flags = 0; | 3480 int opt_flags = 0; |
3462 int vimvaridx = -1; | 3481 int vimvaridx = -1; |
3463 int oplen = 0; | 3482 int oplen = 0; |
3464 int heredoc = FALSE; | 3483 int heredoc = FALSE; |
3465 type_T *type; | 3484 type_T *type = &t_any; |
3466 lvar_T *lvar; | 3485 lvar_T *lvar; |
3467 char_u *name; | 3486 char_u *name; |
3468 char_u *sp; | 3487 char_u *sp; |
3469 int has_type = FALSE; | 3488 int has_type = FALSE; |
3470 int is_decl = cmdidx == CMD_let || cmdidx == CMD_const; | 3489 int is_decl = cmdidx == CMD_let || cmdidx == CMD_const; |
3530 type = &t_number; // both number and boolean option | 3549 type = &t_number; // both number and boolean option |
3531 } | 3550 } |
3532 else if (*arg == '$') | 3551 else if (*arg == '$') |
3533 { | 3552 { |
3534 dest = dest_env; | 3553 dest = dest_env; |
3554 type = &t_string; | |
3535 if (is_decl) | 3555 if (is_decl) |
3536 { | 3556 { |
3537 semsg(_("E1065: Cannot declare an environment variable: %s"), name); | 3557 semsg(_("E1065: Cannot declare an environment variable: %s"), name); |
3538 goto theend; | 3558 goto theend; |
3539 } | 3559 } |
3544 { | 3564 { |
3545 emsg_invreg(arg[1]); | 3565 emsg_invreg(arg[1]); |
3546 goto theend; | 3566 goto theend; |
3547 } | 3567 } |
3548 dest = dest_reg; | 3568 dest = dest_reg; |
3569 type = &t_string; | |
3549 if (is_decl) | 3570 if (is_decl) |
3550 { | 3571 { |
3551 semsg(_("E1066: Cannot declare a register: %s"), name); | 3572 semsg(_("E1066: Cannot declare a register: %s"), name); |
3552 goto theend; | 3573 goto theend; |
3553 } | 3574 } |
3561 goto theend; | 3582 goto theend; |
3562 } | 3583 } |
3563 } | 3584 } |
3564 else if (STRNCMP(arg, "v:", 2) == 0) | 3585 else if (STRNCMP(arg, "v:", 2) == 0) |
3565 { | 3586 { |
3587 typval_T *vtv; | |
3588 | |
3566 vimvaridx = find_vim_var(name + 2); | 3589 vimvaridx = find_vim_var(name + 2); |
3567 if (vimvaridx < 0) | 3590 if (vimvaridx < 0) |
3568 { | 3591 { |
3569 semsg(_(e_var_notfound), arg); | 3592 semsg(_(e_var_notfound), arg); |
3570 goto theend; | 3593 goto theend; |
3571 } | 3594 } |
3572 dest = dest_vimvar; | 3595 dest = dest_vimvar; |
3596 vtv = get_vim_var_tv(vimvaridx); | |
3597 type = typval2type(vtv); | |
3573 if (is_decl) | 3598 if (is_decl) |
3574 { | 3599 { |
3575 semsg(_("E1064: Cannot declare a v: variable: %s"), name); | 3600 semsg(_("E1064: Cannot declare a v: variable: %s"), name); |
3576 goto theend; | 3601 goto theend; |
3577 } | 3602 } |
3623 if (is_decl && *p == ':') | 3648 if (is_decl && *p == ':') |
3624 { | 3649 { |
3625 // parse optional type: "let var: type = expr" | 3650 // parse optional type: "let var: type = expr" |
3626 p = skipwhite(p + 1); | 3651 p = skipwhite(p + 1); |
3627 type = parse_type(&p, cctx->ctx_type_list); | 3652 type = parse_type(&p, cctx->ctx_type_list); |
3628 if (type == NULL) | |
3629 goto theend; | |
3630 has_type = TRUE; | 3653 has_type = TRUE; |
3631 } | 3654 } |
3632 else if (idx < 0) | 3655 else if (idx >= 0) |
3633 { | |
3634 // global and new local default to "any" type | |
3635 type = &t_any; | |
3636 } | |
3637 else | |
3638 { | 3656 { |
3639 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; | 3657 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; |
3640 type = lvar->lv_type; | 3658 type = lvar->lv_type; |
3641 } | 3659 } |
3642 } | 3660 } |
3698 list_free(l); | 3716 list_free(l); |
3699 p += STRLEN(p); | 3717 p += STRLEN(p); |
3700 } | 3718 } |
3701 else if (oplen > 0) | 3719 else if (oplen > 0) |
3702 { | 3720 { |
3703 int r; | 3721 int r; |
3722 type_T *stacktype; | |
3723 garray_T *stack; | |
3704 | 3724 |
3705 // for "+=", "*=", "..=" etc. first load the current value | 3725 // for "+=", "*=", "..=" etc. first load the current value |
3706 if (*op != '=') | 3726 if (*op != '=') |
3707 { | 3727 { |
3708 switch (dest) | 3728 switch (dest) |
3709 { | 3729 { |
3710 case dest_option: | 3730 case dest_option: |
3711 // TODO: check the option exists | 3731 // TODO: check the option exists |
3712 generate_LOAD(cctx, ISN_LOADOPT, 0, name + 1, type); | 3732 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type); |
3713 break; | 3733 break; |
3714 case dest_global: | 3734 case dest_global: |
3715 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); | 3735 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type); |
3716 break; | 3736 break; |
3717 case dest_script: | 3737 case dest_script: |
3744 if (new_local) | 3764 if (new_local) |
3745 ++cctx->ctx_locals.ga_len; | 3765 ++cctx->ctx_locals.ga_len; |
3746 if (r == FAIL) | 3766 if (r == FAIL) |
3747 goto theend; | 3767 goto theend; |
3748 | 3768 |
3769 stack = &cctx->ctx_type_stack; | |
3770 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; | |
3749 if (idx >= 0 && (is_decl || !has_type)) | 3771 if (idx >= 0 && (is_decl || !has_type)) |
3750 { | 3772 { |
3751 garray_T *stack = &cctx->ctx_type_stack; | |
3752 type_T *stacktype = | |
3753 ((type_T **)stack->ga_data)[stack->ga_len - 1]; | |
3754 | |
3755 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; | 3773 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx; |
3756 if (!has_type) | 3774 if (!has_type) |
3757 { | 3775 { |
3758 if (stacktype->tt_type == VAR_VOID) | 3776 if (stacktype->tt_type == VAR_VOID) |
3759 { | 3777 { |
3765 } | 3783 } |
3766 else | 3784 else |
3767 if (check_type(lvar->lv_type, stacktype, TRUE) == FAIL) | 3785 if (check_type(lvar->lv_type, stacktype, TRUE) == FAIL) |
3768 goto theend; | 3786 goto theend; |
3769 } | 3787 } |
3788 else if (*p != '=' && check_type(type, stacktype, TRUE) == FAIL) | |
3789 goto theend; | |
3770 } | 3790 } |
3771 else if (cmdidx == CMD_const) | 3791 else if (cmdidx == CMD_const) |
3772 { | 3792 { |
3773 emsg(_("E1021: const requires a value")); | 3793 emsg(_("E1021: const requires a value")); |
3774 goto theend; | 3794 goto theend; |