To: vim_dev@googlegroups.com Subject: Patch 8.2.0755 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0755 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. Files: src/eval.c, src/vim9script.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.0754/src/eval.c 2020-05-14 22:41:10.225637575 +0200 --- src/eval.c 2020-05-15 17:26:38.469207375 +0200 *************** *** 2695,2700 **** --- 2695,2702 ---- { if (**arg == '(') // recursive! ret = eval_func(arg, s, len, rettv, flags, NULL); + else if (flags & EVAL_CONSTANT) + ret = FAIL; else if (evaluate) ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); else *** ../vim-8.2.0754/src/vim9script.c 2020-05-10 21:20:25.614465563 +0200 --- src/vim9script.c 2020-05-15 17:53:13.582837887 +0200 *************** *** 37,42 **** --- 37,43 ---- garray_T func_ga; int idx; ufunc_T *ufunc; + int start_called_emsg = called_emsg; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) { *************** *** 66,72 **** // The types are recognized, so that they can be used when compiling a // function. gap = source_get_line_ga(eap->cookie); ! for (;;) { char_u *line; char_u *p; --- 67,73 ---- // The types are recognized, so that they can be used when compiling a // function. gap = source_get_line_ga(eap->cookie); ! while (called_emsg == start_called_emsg) { char_u *line; char_u *p; *************** *** 132,153 **** } else if (checkforcmd(&p, "finish", 4)) { - // TODO: this should not happen below "if false". - // Use "if cond | finish | endif as a workaround. break; } } // Compile the :def functions. ! for (idx = 0; idx < func_ga.ga_len; ++idx) { ufunc = ((ufunc_T **)(func_ga.ga_data))[idx]; compile_def_function(ufunc, FALSE, NULL); } ga_clear(&func_ga); ! // Return to process the commands at the script level. ! source_use_line_ga(eap->cookie); } /* --- 133,161 ---- } else if (checkforcmd(&p, "finish", 4)) { break; } } // Compile the :def functions. ! for (idx = 0; idx < func_ga.ga_len && called_emsg == start_called_emsg; ++idx) { ufunc = ((ufunc_T **)(func_ga.ga_data))[idx]; compile_def_function(ufunc, FALSE, NULL); } ga_clear(&func_ga); ! if (called_emsg == start_called_emsg) ! { ! // Return to process the commands at the script level. ! source_use_line_ga(eap->cookie); ! } ! else ! { ! // If there was an error in the first or second phase then don't ! // execute the script lines. ! do_finish(eap, FALSE); ! } } /* *** ../vim-8.2.0754/src/testdir/test_vim9_script.vim 2020-05-14 23:20:51.305625927 +0200 --- src/testdir/test_vim9_script.vim 2020-05-15 17:56:47.638076471 +0200 *************** *** 494,501 **** def Concat(arg: string): string return name .. arg enddef ! let g:result: string = Concat('bie') ! let g:localname = name export const CONST = 1234 export let exported = 9876 --- 494,501 ---- def Concat(arg: string): string return name .. arg enddef ! g:result = Concat('bie') ! g:localname = name export const CONST = 1234 export let exported = 9876 *************** *** 1747,1756 **** endfunc let val = GetValue() END ! writefile(lines, 'Xfinished') ! assert_fails('source Xfinished', 'E1091:') ! delete('Xfinished') enddef def Test_forward_declaration() --- 1747,1780 ---- endfunc let val = GetValue() END ! CheckScriptFailure(lines, 'E1091:') ! lines =<< trim END ! vim9script ! let var = g:unkown ! END ! CheckScriptFailure(lines, 'E1091:') ! ! " TODO: eventually this would work ! lines =<< trim END ! vim9script ! let var = has('eval') ! END ! CheckScriptFailure(lines, 'E1091:') ! ! " TODO: eventually this would work ! lines =<< trim END ! vim9script ! let var = len('string') ! END ! CheckScriptFailure(lines, 'E1091:') ! ! lines =<< trim END ! vim9script ! let nr: number = 123 ! let var = nr ! END ! CheckScriptFailure(lines, 'E1091:') enddef def Test_forward_declaration() *** ../vim-8.2.0754/src/version.c 2020-05-14 23:20:51.305625927 +0200 --- src/version.c 2020-05-15 17:34:15.631568741 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 755, /**/ -- hundred-and-one symptoms of being an internet addict: 92. It takes you two hours to check all 14 of your mailboxes. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///