Mercurial > vim
comparison src/dict.c @ 20397:c225be44692a v8.2.0753
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Commit: https://github.com/vim/vim/commit/32e351179eacfc84f64cd5029e221582d400bb38
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 14 22:41:15 2020 +0200
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Problem: Vim9: expressions are evaluated in the discovery phase.
Solution: Bail out if an expression is not a constant. Require a type for
declared constants.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 14 May 2020 22:45:04 +0200 |
parents | 0e1dfff4f294 |
children | d9a2e5dcfd9f |
comparison
equal
deleted
inserted
replaced
20396:89228c88b5c4 | 20397:c225be44692a |
---|---|
789 * Allocate a variable for a Dictionary and fill it from "*arg". | 789 * Allocate a variable for a Dictionary and fill it from "*arg". |
790 * "literal" is TRUE for #{key: val} | 790 * "literal" is TRUE for #{key: val} |
791 * Return OK or FAIL. Returns NOTDONE for {expr}. | 791 * Return OK or FAIL. Returns NOTDONE for {expr}. |
792 */ | 792 */ |
793 int | 793 int |
794 eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal) | 794 eval_dict(char_u **arg, typval_T *rettv, int flags, int literal) |
795 { | 795 { |
796 int evaluate = flags & EVAL_EVALUATE; | |
796 dict_T *d = NULL; | 797 dict_T *d = NULL; |
797 typval_T tvkey; | 798 typval_T tvkey; |
798 typval_T tv; | 799 typval_T tv; |
799 char_u *key = NULL; | 800 char_u *key = NULL; |
800 dictitem_T *item; | 801 dictitem_T *item; |
801 char_u *start = skipwhite(*arg + 1); | 802 char_u *start = skipwhite(*arg + 1); |
802 char_u buf[NUMBUFLEN]; | 803 char_u buf[NUMBUFLEN]; |
804 int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; | |
803 | 805 |
804 /* | 806 /* |
805 * First check if it's not a curly-braces thing: {expr}. | 807 * First check if it's not a curly-braces thing: {expr}. |
806 * Must do this without evaluating, otherwise a function may be called | 808 * Must do this without evaluating, otherwise a function may be called |
807 * twice. Unfortunately this means we need to call eval1() twice for the | 809 * twice. Unfortunately this means we need to call eval1() twice for the |
808 * first item. | 810 * first item. |
809 * But {} is an empty Dictionary. | 811 * But {} is an empty Dictionary. |
810 */ | 812 */ |
811 if (*start != '}') | 813 if (!vim9script && *start != '}') |
812 { | 814 { |
813 if (eval1(&start, &tv, FALSE) == FAIL) // recursive! | 815 if (eval1(&start, &tv, 0) == FAIL) // recursive! |
814 return FAIL; | 816 return FAIL; |
815 if (*start == '}') | 817 if (*start == '}') |
816 return NOTDONE; | 818 return NOTDONE; |
817 } | 819 } |
818 | 820 |
828 *arg = skipwhite(*arg + 1); | 830 *arg = skipwhite(*arg + 1); |
829 while (**arg != '}' && **arg != NUL) | 831 while (**arg != '}' && **arg != NUL) |
830 { | 832 { |
831 if ((literal | 833 if ((literal |
832 ? get_literal_key(arg, &tvkey) | 834 ? get_literal_key(arg, &tvkey) |
833 : eval1(arg, &tvkey, evaluate)) == FAIL) // recursive! | 835 : eval1(arg, &tvkey, flags)) == FAIL) // recursive! |
834 goto failret; | 836 goto failret; |
835 | 837 |
836 if (**arg != ':') | 838 if (**arg != ':') |
837 { | 839 { |
838 if (evaluate) | 840 if (evaluate) |
850 goto failret; | 852 goto failret; |
851 } | 853 } |
852 } | 854 } |
853 | 855 |
854 *arg = skipwhite(*arg + 1); | 856 *arg = skipwhite(*arg + 1); |
855 if (eval1(arg, &tv, evaluate) == FAIL) // recursive! | 857 if (eval1(arg, &tv, flags) == FAIL) // recursive! |
856 { | 858 { |
857 if (evaluate) | 859 if (evaluate) |
858 clear_tv(&tvkey); | 860 clear_tv(&tvkey); |
859 goto failret; | 861 goto failret; |
860 } | 862 } |