mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
patch 8.2.3169: Vim9: cannot handle nested inline function
Problem: Vim9: cannot handle nested inline function. Solution: Check for nested inline function. (closes #8575)
This commit is contained in:
parent
378697ac58
commit
5245beb37c
@ -2082,7 +2082,8 @@ def Test_expr7_lambda_block()
|
|||||||
var Func = (nr: number): int => {
|
var Func = (nr: number): int => {
|
||||||
return nr
|
return nr
|
||||||
END
|
END
|
||||||
CheckDefAndScriptFailure(lines, 'E1171', 1) # line nr is function start
|
CheckDefFailure(lines, 'E1171', 0) # line nr is function start
|
||||||
|
CheckScriptFailure(['vim9script'] + lines, 'E1171', 2)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
var Func = (nr: number): int => {
|
var Func = (nr: number): int => {
|
||||||
|
@ -2255,6 +2255,16 @@ def Test_nested_inline_lambda()
|
|||||||
assert_equal('--there', F('unused')('there')('--'))
|
assert_equal('--there', F('unused')('there')('--'))
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
echo range(4)->mapnew((_, v) => {
|
||||||
|
return range(v) ->mapnew((_, s) => {
|
||||||
|
return string(s)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Shadowed(): list<number>
|
def Shadowed(): list<number>
|
||||||
|
@ -634,6 +634,7 @@ get_function_body(
|
|||||||
|| eap->cmdidx == CMD_block;
|
|| eap->cmdidx == CMD_block;
|
||||||
#define MAX_FUNC_NESTING 50
|
#define MAX_FUNC_NESTING 50
|
||||||
char nesting_def[MAX_FUNC_NESTING];
|
char nesting_def[MAX_FUNC_NESTING];
|
||||||
|
char nesting_inline[MAX_FUNC_NESTING];
|
||||||
int nesting = 0;
|
int nesting = 0;
|
||||||
getline_opt_T getline_options;
|
getline_opt_T getline_options;
|
||||||
int indent = 2;
|
int indent = 2;
|
||||||
@ -658,7 +659,8 @@ get_function_body(
|
|||||||
((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL;
|
((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nesting_def[nesting] = vim9_function;
|
nesting_def[0] = vim9_function;
|
||||||
|
nesting_inline[0] = eap->cmdidx == CMD_block;
|
||||||
getline_options = vim9_function
|
getline_options = vim9_function
|
||||||
? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT;
|
? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT;
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -705,10 +707,10 @@ get_function_body(
|
|||||||
SOURCING_LNUM = sourcing_lnum_top;
|
SOURCING_LNUM = sourcing_lnum_top;
|
||||||
if (skip_until != NULL)
|
if (skip_until != NULL)
|
||||||
semsg(_(e_missing_heredoc_end_marker_str), skip_until);
|
semsg(_(e_missing_heredoc_end_marker_str), skip_until);
|
||||||
|
else if (nesting_inline[nesting])
|
||||||
|
emsg(_(e_missing_end_block));
|
||||||
else if (eap->cmdidx == CMD_def)
|
else if (eap->cmdidx == CMD_def)
|
||||||
emsg(_(e_missing_enddef));
|
emsg(_(e_missing_enddef));
|
||||||
else if (eap->cmdidx == CMD_block)
|
|
||||||
emsg(_(e_missing_end_block));
|
|
||||||
else
|
else
|
||||||
emsg(_("E126: Missing :endfunction"));
|
emsg(_("E126: Missing :endfunction"));
|
||||||
goto theend;
|
goto theend;
|
||||||
@ -765,7 +767,8 @@ get_function_body(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
char_u *end;
|
||||||
|
|
||||||
// skip ':' and blanks
|
// skip ':' and blanks
|
||||||
for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
|
for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
|
||||||
@ -773,7 +776,7 @@ get_function_body(
|
|||||||
|
|
||||||
// Check for "endfunction", "enddef" or "}".
|
// Check for "endfunction", "enddef" or "}".
|
||||||
// When a ":" follows it must be a dict key; "enddef: value,"
|
// When a ":" follows it must be a dict key; "enddef: value,"
|
||||||
if ((nesting == 0 && eap->cmdidx == CMD_block)
|
if (nesting_inline[nesting]
|
||||||
? *p == '}'
|
? *p == '}'
|
||||||
: (checkforcmd(&p, nesting_def[nesting]
|
: (checkforcmd(&p, nesting_def[nesting]
|
||||||
? "enddef" : "endfunction", 4)
|
? "enddef" : "endfunction", 4)
|
||||||
@ -857,6 +860,31 @@ get_function_body(
|
|||||||
{
|
{
|
||||||
++nesting;
|
++nesting;
|
||||||
nesting_def[nesting] = (c == 'd');
|
nesting_def[nesting] = (c == 'd');
|
||||||
|
nesting_inline[nesting] = FALSE;
|
||||||
|
indent += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for nested inline function.
|
||||||
|
end = p + STRLEN(p) - 1;
|
||||||
|
while (end > p && VIM_ISWHITE(*end))
|
||||||
|
--end;
|
||||||
|
if (*end == '{')
|
||||||
|
{
|
||||||
|
--end;
|
||||||
|
while (end > p && VIM_ISWHITE(*end))
|
||||||
|
--end;
|
||||||
|
if (end > p - 2 && end[-1] == '=' && end[0] == '>')
|
||||||
|
{
|
||||||
|
// found trailing "=> {", start of an inline function
|
||||||
|
if (nesting == MAX_FUNC_NESTING - 1)
|
||||||
|
emsg(_(e_function_nesting_too_deep));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++nesting;
|
||||||
|
nesting_def[nesting] = TRUE;
|
||||||
|
nesting_inline[nesting] = TRUE;
|
||||||
indent += 2;
|
indent += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -755,6 +755,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 */
|
||||||
|
/**/
|
||||||
|
3169,
|
||||||
/**/
|
/**/
|
||||||
3168,
|
3168,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user