From: Bram Moolenaar Date: Thu, 5 May 2022 14:20:03 +0000 (+0100) Subject: patch 8.2.4871: Vim9: in :def function no error for misplaced range X-Git-Tag: v8.2.4871 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09d9421b673366e5f6e56fbf74204a1c316fdea2;p=vim patch 8.2.4871: Vim9: in :def function no error for misplaced range Problem: Vim9: in :def function no error for using a range with a command that does not accept one. Solution: Check for the command to accept a range. (closes #10330) --- diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index dd33a923a..4fa690450 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -67,6 +67,29 @@ def Test_range_only() endif enddef +def Test_invalid_range() + var lines =<< trim END + :123 eval 1 + 2 + END + v9.CheckDefAndScriptFailure(lines, 'E481:', 1) + + lines =<< trim END + :123 if true + endif + END + v9.CheckDefAndScriptFailure(lines, 'E481:', 1) + + lines =<< trim END + :123 echo 'yes' + END + v9.CheckDefAndScriptFailure(lines, 'E481:', 1) + + lines =<< trim END + :123 cd there + END + v9.CheckDefAndScriptFailure(lines, 'E481:', 1) +enddef + let g:alist = [7] let g:astring = 'text' let g:anumber = 123 diff --git a/src/version.c b/src/version.c index 3f7825eee..f0269e44d 100644 --- a/src/version.c +++ b/src/version.c @@ -746,6 +746,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 4871, /**/ 4870, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index 8b22a8db2..b0cf6a787 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3080,6 +3080,11 @@ compile_def_function( ea.forceit = TRUE; p = skipwhite(p + 1); } + if ((ea.argt & EX_RANGE) == 0 && ea.addr_count > 0) + { + emsg(_(e_no_range_allowed)); + goto erret; + } } switch (ea.cmdidx)