comparison src/vim9script.c @ 20401:918b9a05cf35 v8.2.0755

patch 8.2.0755: Vim9: No error when variable initializer is not a constant Commit: https://github.com/vim/vim/commit/227a69de1e0f9457a9fc9e098d999304faff55f8 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 15 18:17:28 2020 +0200 patch 8.2.0755: Vim9: No error when variable initializer is not a constant Problem: Vim9: No error when variable initializer is not a constant. Solution: Return FAIL when trying to get a variable value. Do not execute a script when an error is deteted in the first or second phase.
author Bram Moolenaar <Bram@vim.org>
date Fri, 15 May 2020 18:30:04 +0200
parents 680296770464
children 7fb80f486aad
comparison
equal deleted inserted replaced
20400:9a53e38d4abb 20401:918b9a05cf35
35 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); 35 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
36 garray_T *gap; 36 garray_T *gap;
37 garray_T func_ga; 37 garray_T func_ga;
38 int idx; 38 int idx;
39 ufunc_T *ufunc; 39 ufunc_T *ufunc;
40 int start_called_emsg = called_emsg;
40 41
41 if (!getline_equal(eap->getline, eap->cookie, getsourceline)) 42 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
42 { 43 {
43 emsg(_("E1038: vim9script can only be used in a script")); 44 emsg(_("E1038: vim9script can only be used in a script"));
44 return; 45 return;
64 // - variable and constant declarations 65 // - variable and constant declarations
65 // - imports 66 // - imports
66 // The types are recognized, so that they can be used when compiling a 67 // The types are recognized, so that they can be used when compiling a
67 // function. 68 // function.
68 gap = source_get_line_ga(eap->cookie); 69 gap = source_get_line_ga(eap->cookie);
69 for (;;) 70 while (called_emsg == start_called_emsg)
70 { 71 {
71 char_u *line; 72 char_u *line;
72 char_u *p; 73 char_u *p;
73 74
74 if (ga_grow(gap, 1) == FAIL) 75 if (ga_grow(gap, 1) == FAIL)
130 vim_free(((char_u **)(gap->ga_data))[--gap->ga_len]); 131 vim_free(((char_u **)(gap->ga_data))[--gap->ga_len]);
131 ((char_u **)(gap->ga_data))[gap->ga_len++] = NULL; 132 ((char_u **)(gap->ga_data))[gap->ga_len++] = NULL;
132 } 133 }
133 else if (checkforcmd(&p, "finish", 4)) 134 else if (checkforcmd(&p, "finish", 4))
134 { 135 {
135 // TODO: this should not happen below "if false".
136 // Use "if cond | finish | endif as a workaround.
137 break; 136 break;
138 } 137 }
139 } 138 }
140 139
141 // Compile the :def functions. 140 // Compile the :def functions.
142 for (idx = 0; idx < func_ga.ga_len; ++idx) 141 for (idx = 0; idx < func_ga.ga_len && called_emsg == start_called_emsg; ++idx)
143 { 142 {
144 ufunc = ((ufunc_T **)(func_ga.ga_data))[idx]; 143 ufunc = ((ufunc_T **)(func_ga.ga_data))[idx];
145 compile_def_function(ufunc, FALSE, NULL); 144 compile_def_function(ufunc, FALSE, NULL);
146 } 145 }
147 ga_clear(&func_ga); 146 ga_clear(&func_ga);
148 147
149 // Return to process the commands at the script level. 148 if (called_emsg == start_called_emsg)
150 source_use_line_ga(eap->cookie); 149 {
150 // Return to process the commands at the script level.
151 source_use_line_ga(eap->cookie);
152 }
153 else
154 {
155 // If there was an error in the first or second phase then don't
156 // execute the script lines.
157 do_finish(eap, FALSE);
158 }
151 } 159 }
152 160
153 /* 161 /*
154 * ":export let Name: type" 162 * ":export let Name: type"
155 * ":export const Name: type" 163 * ":export const Name: type"