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/vim9compile.c b/src/vim9compile.c
index 99246e0..4b294df 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2869,14 +2869,14 @@
{
// Can be "[1, 2, 3]->Func()".
- if (get_list_tv(&p, &rettv, FALSE, FALSE) == FAIL)
+ if (get_list_tv(&p, &rettv, 0, FALSE) == FAIL)
p = arg;
}
else if (p == arg && *arg == '#' && arg[1] == '{')
{
// Can be "#{a: 1}->Func()".
++p;
- if (eval_dict(&p, &rettv, FALSE, TRUE) == FAIL)
+ if (eval_dict(&p, &rettv, 0, TRUE) == FAIL)
p = arg;
}
else if (p == arg && *arg == '{')
@@ -2886,7 +2886,7 @@
// Can be "{x -> ret}()".
// Can be "{'a': 1}->Func()".
if (ret == NOTDONE)
- ret = eval_dict(&p, &rettv, FALSE, FALSE);
+ ret = eval_dict(&p, &rettv, 0, FALSE);
if (ret != OK)
p = arg;
}