mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.2173: Vim9: crash when compiling for statement and non-existing type
Problem: Vim9: Vim crashes when compiling a for statement with a non-existing type Solution: Error out when lhs_type is not null closes: #13703 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
a185a31fc0
commit
062bb6b909
@@ -2698,6 +2698,37 @@ def Test_for_loop_fails()
|
|||||||
v9.CheckDefSuccess(lines)
|
v9.CheckDefSuccess(lines)
|
||||||
|
|
||||||
v9.CheckDefFailure(['for x in range(3)'] + lines + ['endfor'], 'E1306:')
|
v9.CheckDefFailure(['for x in range(3)'] + lines + ['endfor'], 'E1306:')
|
||||||
|
|
||||||
|
# Test for too many for loops
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
for a in range(1)
|
||||||
|
for b in range(1)
|
||||||
|
for c in range(1)
|
||||||
|
for d in range(1)
|
||||||
|
for e in range(1)
|
||||||
|
for f in range(1)
|
||||||
|
for g in range(1)
|
||||||
|
for h in range(1)
|
||||||
|
for i in range(1)
|
||||||
|
for j in range(1)
|
||||||
|
for k in range(1)
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckSourceFailure(lines, 'E1306: Loop nesting too deep', 11)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_for_loop_script_var()
|
def Test_for_loop_script_var()
|
||||||
@@ -4796,6 +4827,85 @@ def Test_defer_skipped()
|
|||||||
v9.CheckSourceSuccess(lines)
|
v9.CheckSourceSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
" Test for using defer without parenthesis for the function name
|
||||||
|
def Test_defer_func_without_paren()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
defer Bar
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckScriptFailure(lines, 'E107: Missing parentheses: Bar', 1)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
" Test for using defer without parenthesis for the function name
|
||||||
|
def Test_defer_non_existing_func()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
defer Bar()
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckScriptFailure(lines, 'E1001: Variable not found: Bar', 1)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
" Test for using defer with an invalid function name
|
||||||
|
def Test_defer_invalid_func()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
var Abc = 10
|
||||||
|
defer Abc()
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckScriptFailure(lines, 'E129: Function name required', 2)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
" Test for using defer with an invalid argument to a function
|
||||||
|
def Test_defer_invalid_func_arg()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Bar(x: number)
|
||||||
|
enddef
|
||||||
|
def Foo()
|
||||||
|
defer Bar(a)
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckScriptFailure(lines, 'E1001: Variable not found: a', 1)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
" Test for using an non-existing type in a "for" statement.
|
||||||
|
def Test_invalid_type_in_for()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
for b: x in range(10)
|
||||||
|
endfor
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckSourceFailure(lines, 'E1010: Type not recognized: x in range(10)', 1)
|
||||||
|
enddef
|
||||||
|
|
||||||
|
" Test for using a line break between the variable name and the type in a for
|
||||||
|
" statement.
|
||||||
|
def Test_for_stmt_space_before_type()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def Foo()
|
||||||
|
for a
|
||||||
|
:number in range(10)
|
||||||
|
endfor
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
v9.CheckSourceFailure(lines, 'E1059: No white space allowed before colon: :number in range(10)', 2)
|
||||||
|
enddef
|
||||||
|
|
||||||
" Keep this last, it messes up highlighting.
|
" Keep this last, it messes up highlighting.
|
||||||
def Test_substitute_cmd()
|
def Test_substitute_cmd()
|
||||||
new
|
new
|
||||||
|
@@ -704,6 +704,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 */
|
||||||
|
/**/
|
||||||
|
2173,
|
||||||
/**/
|
/**/
|
||||||
2172,
|
2172,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1088,6 +1088,8 @@ compile_for(char_u *arg_start, cctx_T *cctx)
|
|||||||
}
|
}
|
||||||
p = skipwhite(p + 1);
|
p = skipwhite(p + 1);
|
||||||
lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
|
lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
|
||||||
|
if (lhs_type == NULL)
|
||||||
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_var_dest(name, &dest, CMD_for, &opt_flags,
|
if (get_var_dest(name, &dest, CMD_for, &opt_flags,
|
||||||
|
Reference in New Issue
Block a user