Compare commits

...

6 Commits

Author SHA1 Message Date
Bram Moolenaar
b90ac5e96e patch 8.2.3009: startup test may hang
Problem:    Startup test may hang.
Solution:   Do not run the test in the GUI.
2021-06-16 10:59:36 +02:00
Bram Moolenaar
55b6b60b69 patch 8.2.3008: startup test may hang
Problem:    Startup test may hang.
Solution:   Add quit command in the script.
2021-06-15 23:05:59 +02:00
Bram Moolenaar
61a417b7c1 patch 8.2.3007: Vim9: test for void value fails
Problem:    Vim9: test for void value fails.
Solution:   Adjust expected error.  Do not make a copy of void.
2021-06-15 22:54:28 +02:00
Bram Moolenaar
a97c36310f patch 8.2.3006: crash when echoing a value very early
Problem:    Crash when echoing a value very early. (Naruhiko Nishino)
Solution:   Do not use a NUL to truncate the message, make a copy.
            (closes #8388)
2021-06-15 22:39:11 +02:00
Bram Moolenaar
f57b43c230 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Problem:    Vim9: using a void value does not give a proper error message.
Solution:   Give a clear error message. (clodes #8387)
2021-06-15 22:13:27 +02:00
Bram Moolenaar
8ac681a280 patch 8.2.3004: Vim9: error for missing colon given while skipping
Problem:    Vim9: error for missing colon given while skipping.
Solution:   Do not give the error when skipping. (closes #8385)
2021-06-15 20:06:34 +02:00
12 changed files with 127 additions and 61 deletions

View File

@@ -1844,7 +1844,7 @@ do_one_cmd(
// If a ':' before the range is missing, give a clearer error
// message.
if (ar > ea.cmd)
if (ar > ea.cmd && !ea.skip)
{
semsg(_(e_colon_required_before_range_str), ea.cmd);
goto doend;

View File

@@ -2751,19 +2751,21 @@ msg_puts_printf(char_u *str, int maxlen)
if (*p != NUL && !(silent_mode && p_verbose == 0))
{
int c = -1;
char_u *tofree = NULL;
if (maxlen > 0 && STRLEN(p) > (size_t)maxlen)
{
c = p[maxlen];
p[maxlen] = 0;
tofree = vim_strnsave(p, (size_t)maxlen);
p = tofree;
}
if (p != NULL)
{
if (info_message)
mch_msg((char *)p);
else
mch_errmsg((char *)p);
vim_free(tofree);
}
if (info_message)
mch_msg((char *)p);
else
mch_errmsg((char *)p);
if (c != -1)
p[maxlen] = c;
}
msg_didout = TRUE; // assume that line is not empty

View File

@@ -86,13 +86,13 @@ func Test_empty()
endfunc
func Test_test_void()
call assert_fails('echo 1 == test_void()', 'E685:')
call assert_fails('echo 1 == test_void()', 'E1031:')
if has('float')
call assert_fails('echo 1.0 == test_void()', 'E685:')
call assert_fails('echo 1.0 == test_void()', 'E1031:')
endif
call assert_fails('let x = json_encode(test_void())', 'E685:')
call assert_fails('let x = copy(test_void())', 'E685:')
call assert_fails('let x = copy([test_void()])', 'E685:')
call assert_fails('let x = copy([test_void()])', 'E1031:')
endfunc
func Test_len()

View File

@@ -1301,4 +1301,20 @@ func Test_write_in_vimrc()
call delete('Xvimrc')
endfunc
func Test_echo_true_in_cmd()
CheckNotGui
let lines =<< trim END
echo v:true
call writefile(['done'], 'Xresult')
quit
END
call writefile(lines, 'Xscript')
if RunVim([], [], '--cmd "source Xscript"')
call assert_equal(['done'], readfile('Xresult'))
endif
call delete('Xscript')
call delete('Xresult')
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -117,7 +117,7 @@ def Test_disassemble_exec_expr()
'\d 2STRING stack\[-1\]\_s*' ..
'\d\+ PUSHS ".txt"\_s*' ..
'\d\+ EXECCONCAT 4\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -133,7 +133,7 @@ EOF
assert_match('<SNR>\d*_PyHeredoc.*' ..
" python3 << EOF^@ print('hello')^@EOF\\_s*" ..
'\d EXEC_SPLIT python3 << EOF^@ print(''hello'')^@EOF\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
endif
@@ -153,7 +153,7 @@ def Test_disassemble_substitute()
'\d SUBSTITUTE :%s/a/\\=expr/&g#c\_s*' ..
' 0 LOAD $0\_s*' ..
' -------------\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -181,7 +181,7 @@ def Test_disassemble_seachpair()
' -------------\_s*' ..
'\d BCALL searchpair(argc 5)\_s*' ..
'\d DROP\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -209,7 +209,7 @@ def Test_disassemble_redir_var()
'\d REDIR END\_s*' ..
'\d CONCAT\_s*' ..
'\d STORE $0\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -228,7 +228,7 @@ def Test_disassemble_cexpr()
'\d CEXPR pre cexpr\_s*' ..
'\d LOAD $0\_s*' ..
'\d CEXPR core cexpr "cexpr errors"\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -244,7 +244,7 @@ def Test_disassemble_yank_range()
'\d EXEC norm! m\[jjm\]\_s*' ..
' :''\[,''\]yank\_s*' ..
'\d EXEC :''\[,''\]yank\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -258,7 +258,7 @@ def Test_disassemble_put_expr()
' :3put ="text"\_s*' ..
'\d PUSHS "text"\_s*' ..
'\d PUT = 3\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -272,7 +272,7 @@ def Test_disassemble_put_range()
' :$-2put a\_s*' ..
'\d RANGE $-2\_s*' ..
'\d PUT a range\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -390,7 +390,7 @@ def Test_disassemble_store_member()
'\d\+ PUSHNR 1\_s*' ..
'\d\+ LOAD $2\_s*' ..
'\d\+ STOREINDEX blob\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -413,7 +413,7 @@ def Test_disassemble_store_index()
'\d LOAD $0\_s*' ..
'\d MEMBER dd\_s*' ..
'\d STOREINDEX any\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -448,7 +448,7 @@ def Test_disassemble_list_assign()
'\d\+ STORE $1\_s*' ..
'\d\+ SLICE 2\_s*' ..
'\d\+ STORE $2\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -476,7 +476,7 @@ def Test_disassemble_list_add()
'\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
'\d\+ LISTAPPEND\_s*' ..
'\d\+ DROP\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -503,7 +503,7 @@ def Test_disassemble_blob_add()
'\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
'\d\+ BLOBAPPEND\_s*' ..
'\d\+ DROP\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -530,7 +530,7 @@ def Test_disassemble_blob_index_slice()
'\d\+ PUSHNR 2\_s*' ..
'\d\+ BLOBSLICE\_s*' ..
'\d\+ ECHO 1\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -720,7 +720,7 @@ def Test_disassemble_closure()
'\d LOAD arg\[-1\]\_s*' ..
'\d CONCAT\_s*' ..
'\d STOREOUTER level 1 $0\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
res = execute('disass g:Get')
@@ -754,7 +754,7 @@ def Test_disassemble_pcall()
'\d PCALL top (argc 1)\_s*' ..
'\d PCALL end\_s*' ..
'\d DROP\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -1012,7 +1012,7 @@ def Test_disassemble_function()
'\d PUSHS "UserFunc"\_s*' ..
'\d BCALL funcref(argc 1)\_s*' ..
'\d STORE $2\_s*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
enddef
@@ -1039,7 +1039,7 @@ def Test_disassemble_channel()
'var chan1: channel\_s*' ..
'\d PUSHCHANNEL 0\_s*' ..
'\d STORE $2\_s*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
enddef
@@ -1111,7 +1111,7 @@ def Test_disassemble_nested_func()
'echomsg "inner"\_s*' ..
'enddef\_s*' ..
'\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
enddef
@@ -1133,7 +1133,7 @@ def Test_disassemble_nested_def_list()
'\d DEF /Info\_s*' ..
'def /Info/\_s*' ..
'\d DEF /Info/\_s*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
enddef
@@ -1264,7 +1264,7 @@ def Test_disassemble_for_loop_unpack()
'endfor\_s*' ..
'\d\+ JUMP -> 8\_s*' ..
'\d\+ DROP\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
instr)
enddef
@@ -1321,7 +1321,7 @@ def Test_disassemble_for_loop_continue()
'endfor\_s*' ..
'21 JUMP -> 4\_s*' ..
'\d\+ DROP\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
instr)
enddef
@@ -1341,7 +1341,7 @@ def Test_disassemble_typecast()
'\d NEWLIST size 2\_s*' ..
'\d SETTYPE list<number>\_s*' ..
'\d STORE $0\_s*' ..
'\d RETURN 0\_s*',
'\d RETURN void\_s*',
instr)
enddef
@@ -1828,7 +1828,7 @@ def Test_dsassemble_falsy_op()
'echo "" ?? "empty string"\_s*' ..
'\d\+ PUSHS "empty string"\_s*' ..
'\d\+ ECHO 1\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -1855,7 +1855,7 @@ def Test_disassemble_compare_const()
'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
'\d PUSHNR 42.*' ..
'\d ECHO 1.*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
else
# condition false, function just returns
@@ -1863,7 +1863,7 @@ def Test_disassemble_compare_const()
'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
'echo 42[ \n]*' ..
'endif[ \n]*' ..
'\d RETURN 0',
'\d RETURN void',
instr)
endif
@@ -1901,7 +1901,7 @@ def Test_disassemble_execute()
'\d\+ LOAD $1\_s*' ..
'\d\+ CONCAT\_s*' ..
'\d\+ EXECUTE 1\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -1920,7 +1920,7 @@ def Test_disassemble_echomsg()
"echoerr 'went' .. 'wrong'\\_s*" ..
'\d PUSHS "wentwrong"\_s*' ..
'\d ECHOERR 1\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -2029,7 +2029,7 @@ def Test_shuffle()
'\d SHUFFLE 2 up 1\_s*' ..
'\d BCALL append(argc 2)\_s*' ..
'\d DROP\_s*' ..
'\d RETURN 0',
'\d RETURN void',
res)
enddef
@@ -2052,7 +2052,7 @@ def Test_silent()
'\d PUSHS "error"\_s*' ..
'\d ECHOERR 1\_s*' ..
'\d CMDMOD_REV\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -2081,7 +2081,7 @@ def Test_silent_if()
'\d\+ CMDMOD_REV\_s*' ..
'\d\+ JUMP_IF_FALSE -> \d\+\_s*' ..
'endif\_s*' ..
'\d\+ RETURN 0',
'\d\+ RETURN void',
res)
enddef
@@ -2104,7 +2104,7 @@ def Test_silent_for()
'endfor\_s*' ..
'\d JUMP -> 5\_s*' ..
'8 DROP\_s*' ..
'\d RETURN 0\_s*',
'\d RETURN void\_s*',
res)
enddef
@@ -2125,7 +2125,7 @@ def Test_silent_while()
'endwhile\_s*' ..
'\d JUMP -> 0\_s*' ..
'6 RETURN 0\_s*',
'6 RETURN void\_s*',
res)
enddef

View File

@@ -2967,6 +2967,20 @@ def Test_expr7_method_call()
assert_equal([1, 2, 3], sorted)
END
CheckDefAndScriptSuccess(lines)
lines =<< trim END
def RetVoid()
enddef
RetVoid()->byte2line()
END
CheckDefExecAndScriptFailure(lines, 'E1031:')
lines =<< trim END
def RetVoid()
enddef
RetVoid()->byteidx(3)
END
CheckDefExecAndScriptFailure(lines, 'E1031:')
enddef

View File

@@ -590,6 +590,19 @@ def Test_try_catch_throw()
return 2
enddef
assert_equal(4, ReturnInFinally())
var lines =<< trim END
vim9script
try
acos('0.5')
->setline(1)
catch
g:caught = v:exception
endtry
END
CheckScriptSuccess(lines)
assert_match('E808: Number or Float required', g:caught)
unlet g:caught
enddef
" :while at the very start of a function that :continue jumps to

View File

@@ -238,9 +238,11 @@ tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
case VAR_BLOB:
emsg(_("E974: Using a Blob as a Number"));
break;
case VAR_VOID:
emsg(_(e_cannot_use_void_value));
break;
case VAR_UNKNOWN:
case VAR_ANY:
case VAR_VOID:
case VAR_INSTR:
internal_error_no_abort("tv_get_number(UNKNOWN)");
break;
@@ -294,7 +296,7 @@ tv_get_bool_chk(typval_T *varp, int *denote)
return tv_get_bool_or_number_chk(varp, denote, TRUE);
}
#ifdef FEAT_FLOAT
#if defined(FEAT_FLOAT) || defined(PROTO)
float_T
tv_get_float(typval_T *varp)
{
@@ -336,9 +338,11 @@ tv_get_float(typval_T *varp)
case VAR_BLOB:
emsg(_("E975: Using a Blob as a Float"));
break;
case VAR_VOID:
emsg(_(e_cannot_use_void_value));
break;
case VAR_UNKNOWN:
case VAR_ANY:
case VAR_VOID:
case VAR_INSTR:
internal_error_no_abort("tv_get_float(UNKNOWN)");
break;
@@ -501,9 +505,11 @@ tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict)
return channel_to_string_buf(varp, buf);
#endif
break;
case VAR_VOID:
emsg(_(e_cannot_use_void_value));
break;
case VAR_UNKNOWN:
case VAR_ANY:
case VAR_VOID:
case VAR_INSTR:
semsg(_(e_using_invalid_value_as_string_str),
vartype_name(varp->v_type));
@@ -657,9 +663,11 @@ copy_tv(typval_T *from, typval_T *to)
++to->vval.v_dict->dv_refcount;
}
break;
case VAR_VOID:
emsg(_(e_cannot_use_void_value));
break;
case VAR_UNKNOWN:
case VAR_ANY:
case VAR_VOID:
internal_error_no_abort("copy_tv(UNKNOWN)");
break;
}

View File

@@ -750,6 +750,18 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3009,
/**/
3008,
/**/
3007,
/**/
3006,
/**/
3005,
/**/
3004,
/**/
3003,
/**/

View File

@@ -91,7 +91,7 @@ typedef enum {
ISN_PCALL, // call partial, use isn_arg.pfunc
ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set
ISN_RETURN, // return, result is on top of stack
ISN_RETURN_ZERO, // Push zero, then return
ISN_RETURN_VOID, // Push void, then return
ISN_FUNCREF, // push a function ref to dfunc isn_arg.funcref
ISN_NEWFUNC, // create a global function from a lambda function
ISN_DEF, // list functions

View File

@@ -9679,8 +9679,8 @@ nextline:
goto erret;
}
// Return zero if there is no return at the end.
generate_instr(&cctx, ISN_RETURN_ZERO);
// Return void if there is no return at the end.
generate_instr(&cctx, ISN_RETURN_VOID);
}
// When compiled with ":silent!" and there was an error don't consider the
@@ -10047,7 +10047,7 @@ delete_instr(isn_T *isn)
case ISN_REDIREND:
case ISN_REDIRSTART:
case ISN_RETURN:
case ISN_RETURN_ZERO:
case ISN_RETURN_VOID:
case ISN_SHUFFLE:
case ISN_SLICE:
case ISN_STORE:

View File

@@ -2815,17 +2815,18 @@ exec_instructions(ectx_T *ectx)
}
break;
// return from a :def function call
case ISN_RETURN_ZERO:
// return from a :def function call without a value
case ISN_RETURN_VOID:
if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
goto theend;
tv = STACK_TV_BOT(0);
++ectx->ec_stack.ga_len;
tv->v_type = VAR_NUMBER;
tv->v_type = VAR_VOID;
tv->vval.v_number = 0;
tv->v_lock = 0;
// FALLTHROUGH
// return from a :def function call with what is on the stack
case ISN_RETURN:
{
garray_T *trystack = &ectx->ec_trystack;
@@ -5076,8 +5077,8 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
case ISN_RETURN:
smsg("%s%4d RETURN", pfx, current);
break;
case ISN_RETURN_ZERO:
smsg("%s%4d RETURN 0", pfx, current);
case ISN_RETURN_VOID:
smsg("%s%4d RETURN void", pfx, current);
break;
case ISN_FUNCREF:
{