To: vim_dev@googlegroups.com Subject: Patch 8.2.1529 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1529 Problem: Vim9: :elseif may be compiled when not needed. Solution: Do evaluate the :elseif expression. Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1528/src/vim9compile.c 2020-08-27 22:42:59.416097708 +0200 --- src/vim9compile.c 2020-08-27 23:02:54.007756624 +0200 *************** *** 5519,5524 **** --- 5519,5525 ---- isn_T *isn; scope_T *scope = cctx->ctx_scope; ppconst_T ppconst; + skip_T save_skip = cctx->ctx_skip; if (scope == NULL || scope->se_type != IF_SCOPE) { *************** *** 5541,5551 **** --- 5542,5555 ---- // compile "expr"; if we know it evaluates to FALSE skip the block CLEAR_FIELD(ppconst); + if (cctx->ctx_skip == SKIP_YES) + cctx->ctx_skip = SKIP_UNKNOWN; if (compile_expr1(&p, cctx, &ppconst) == FAIL) { clear_ppconst(&ppconst); return NULL; } + cctx->ctx_skip = save_skip; if (scope->se_skip_save == SKIP_YES) clear_ppconst(&ppconst); else if (instr->ga_len == instr_count && ppconst.pp_used == 1) *** ../vim-8.2.1528/src/testdir/test_vim9_expr.vim 2020-08-27 21:33:06.978960755 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-27 23:06:35.214989908 +0200 *************** *** 43,48 **** --- 43,51 ---- var = 0 assert_equal('two', var ? 'one' : 'two') + # with constant condition expression is not evaluated + assert_equal('one', 1 ? 'one' : xxx) + let Some: func = function('len') let Other: func = function('winnr') let Res: func = g:atrue ? Some : Other *************** *** 139,145 **** func Test_expr1_fails() call CheckDefFailure(["let x = 1 ? 'one'"], "Missing ':' after '?'", 1) - call CheckDefFailure(["let x = 1 ? 'one' : xxx"], "E1001:", 1) let msg = "white space required before and after '?'" call CheckDefFailure(["let x = 1? 'one' : 'two'"], msg, 1) --- 142,147 ---- *** ../vim-8.2.1528/src/version.c 2020-08-27 22:42:59.416097708 +0200 --- src/version.c 2020-08-27 23:04:49.807356434 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1529, /**/ -- Facepalm statement #5: "Petrol getting more expensive? Not for me, I'm always tanking for 20 dollars" /// 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 ///