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.
diff --git a/src/dict.c b/src/dict.c
index 54d3110..3824f40 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -791,8 +791,9 @@
* Return OK or FAIL. Returns NOTDONE for {expr}.
*/
int
-eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
+eval_dict(char_u **arg, typval_T *rettv, int flags, int literal)
{
+ int evaluate = flags & EVAL_EVALUATE;
dict_T *d = NULL;
typval_T tvkey;
typval_T tv;
@@ -800,6 +801,7 @@
dictitem_T *item;
char_u *start = skipwhite(*arg + 1);
char_u buf[NUMBUFLEN];
+ int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
/*
* First check if it's not a curly-braces thing: {expr}.
@@ -808,9 +810,9 @@
* first item.
* But {} is an empty Dictionary.
*/
- if (*start != '}')
+ if (!vim9script && *start != '}')
{
- if (eval1(&start, &tv, FALSE) == FAIL) // recursive!
+ if (eval1(&start, &tv, 0) == FAIL) // recursive!
return FAIL;
if (*start == '}')
return NOTDONE;
@@ -830,7 +832,7 @@
{
if ((literal
? get_literal_key(arg, &tvkey)
- : eval1(arg, &tvkey, evaluate)) == FAIL) // recursive!
+ : eval1(arg, &tvkey, flags)) == FAIL) // recursive!
goto failret;
if (**arg != ':')
@@ -852,7 +854,7 @@
}
*arg = skipwhite(*arg + 1);
- if (eval1(arg, &tv, evaluate) == FAIL) // recursive!
+ if (eval1(arg, &tv, flags) == FAIL) // recursive!
{
if (evaluate)
clear_tv(&tvkey);