0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.0583: Vim9: # comment not recognized in :def function

Problem:    Vim9: # comment not recognized in :def function.
Solution:   Recognize and skip # comment.
This commit is contained in:
Bram Moolenaar 2020-04-16 13:00:29 +02:00
parent b4a549fb16
commit cb711abf0f
3 changed files with 51 additions and 30 deletions

View File

@ -63,9 +63,9 @@ def Test_assignment()
let Funky2: func = function('len') let Funky2: func = function('len')
let Party2: func = funcref('Test_syntax') let Party2: func = funcref('Test_syntax')
" type becomes list<any> # type becomes list<any>
let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c'] let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
" type becomes dict<any> # type becomes dict<any>
let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'} let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
g:newvar = 'new' g:newvar = 'new'
@ -104,7 +104,7 @@ def Test_assignment()
call CheckDefFailure(['&notex += 3'], 'E113:') call CheckDefFailure(['&notex += 3'], 'E113:')
call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:') call CheckDefFailure(['&ts ..= "xxx"'], 'E1019:')
call CheckDefFailure(['&path += 3'], 'E1013:') call CheckDefFailure(['&path += 3'], 'E1013:')
" test freeing ISN_STOREOPT # test freeing ISN_STOREOPT
call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:') call CheckDefFailure(['&ts = 3', 'let asdf'], 'E1022:')
&ts = 8 &ts = 8
@ -131,7 +131,7 @@ enddef
def Test_assignment_default() def Test_assignment_default()
" Test default values. # Test default values.
let thebool: bool let thebool: bool
assert_equal(v:false, thebool) assert_equal(v:false, thebool)

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
583,
/**/ /**/
582, 582,
/**/ /**/

View File

@ -5772,7 +5772,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
*/ */
for (;;) for (;;)
{ {
int is_ex_command; int is_ex_command = FALSE;
// Bail out on the first error to avoid a flood of errors and report // Bail out on the first error to avoid a flood of errors and report
// the right line number when inside try/catch. // the right line number when inside try/catch.
@ -5791,6 +5791,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
{ {
line = next_line_from_context(&cctx); line = next_line_from_context(&cctx);
if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len) if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
// beyond the last line
break; break;
} }
emsg_before = called_emsg; emsg_before = called_emsg;
@ -5800,35 +5801,53 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
ea.cmdlinep = &line; ea.cmdlinep = &line;
ea.cmd = skipwhite(line); ea.cmd = skipwhite(line);
// "}" ends a block scope // Some things can be recognized by the first character.
if (*ea.cmd == '}') switch (*ea.cmd)
{ {
scopetype_T stype = cctx.ctx_scope == NULL case '#':
? NO_SCOPE : cctx.ctx_scope->se_type; // "#" starts a comment, but not "#{".
if (ea.cmd[1] != '{')
{
line = (char_u *)"";
continue;
}
break;
if (stype == BLOCK_SCOPE) case '}':
{ {
compile_endblock(&cctx); // "}" ends a block scope
line = ea.cmd; scopetype_T stype = cctx.ctx_scope == NULL
} ? NO_SCOPE : cctx.ctx_scope->se_type;
else
{
emsg(_("E1025: using } outside of a block scope"));
goto erret;
}
if (line != NULL)
line = skipwhite(ea.cmd + 1);
continue;
}
// "{" starts a block scope if (stype == BLOCK_SCOPE)
// "{'a': 1}->func() is something else {
if (*ea.cmd == '{' && ends_excmd(*skipwhite(ea.cmd + 1))) compile_endblock(&cctx);
{ line = ea.cmd;
line = compile_block(ea.cmd, &cctx); }
continue; else
{
emsg(_("E1025: using } outside of a block scope"));
goto erret;
}
if (line != NULL)
line = skipwhite(ea.cmd + 1);
continue;
}
case '{':
// "{" starts a block scope
// "{'a': 1}->func() is something else
if (ends_excmd(*skipwhite(ea.cmd + 1)))
{
line = compile_block(ea.cmd, &cctx);
continue;
}
break;
case ':':
is_ex_command = TRUE;
break;
} }
is_ex_command = *ea.cmd == ':';
/* /*
* COMMAND MODIFIERS * COMMAND MODIFIERS