changeset 20351:680296770464 v8.2.0731

patch 8.2.0731: Vim9: parsing declarations continues after :finish Commit: https://github.com/vim/vim/commit/7e5bd91dc99e1ecb38c4220eaab1a906a69815c2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 10 21:20:29 2020 +0200 patch 8.2.0731: Vim9: parsing declarations continues after :finish Problem: Vim9: parsing declarations continues after :finish. Solution: Bail out when encountering :finish.
author Bram Moolenaar <Bram@vim.org>
date Sun, 10 May 2020 21:30:04 +0200
parents 3362f6227205
children 8ce5690fdb49
files src/testdir/test_vim9_script.vim src/version.c src/vim9script.c
diffstat 3 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1705,6 +1705,23 @@ def Test_vim9_comment_not_compiled()
       ], 'E488:')
 enddef
 
+def Test_finish()
+  let lines =<< trim END
+    vim9script
+    let g:res = 'one'
+    if v:false | finish | endif
+    let g:res = 'two'
+    finish
+    let g:res = 'three'
+  END
+  writefile(lines, 'Xfinished')
+  source Xfinished
+  assert_equal('two', g:res)
+
+  unlet g:res
+  delete('Xfinished')
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    731,
+/**/
     730,
 /**/
     729,
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -130,6 +130,12 @@ ex_vim9script(exarg_T *eap)
 	    vim_free(((char_u **)(gap->ga_data))[--gap->ga_len]);
 	    ((char_u **)(gap->ga_data))[gap->ga_len++] = NULL;
 	}
+	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.