Compare commits

...

22 Commits

Author SHA1 Message Date
Bram Moolenaar
95388e3179 patch 8.2.2022: Vim9: star command recognized errornously
Problem:    Vim9: star command recognized errornously.
Solution:   Give an error for missing colon. (issue #7335)
2020-11-20 21:07:00 +01:00
Bram Moolenaar
eeece9e488 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Problem:    Vim9: get E1099 when autocommand resets did_emsg.
Solution:   Add did_emsg_cumul. (closes #7336)
2020-11-20 19:26:48 +01:00
Bram Moolenaar
bebaa0d5c0 patch 8.2.2020: some compilers do not like the "namespace" argument
Problem:    Some compilers do not like the "namespace" argument.
Solution:   Rename to "use_namespace". (closes #7332)
2020-11-20 18:59:19 +01:00
Bram Moolenaar
80d868ec25 patch 8.2.2019: swap file test fails on MS-Windows
Problem:    Swap file test fails on MS-Windows.
Solution:   Add four to the process ID. (Ken Takata, closes #7333)
2020-11-20 09:10:15 +01:00
Bram Moolenaar
2ea95b61f4 patch 8.2.2018: Vim9: script variable not found from lambda
Problem:    Vim9: script variable not found from lambda.
Solution:   In a lambda also check the script hashtab for a variable without a
            scope. (closes #7329)
2020-11-19 21:47:56 +01:00
Bram Moolenaar
67d1c68f09 patch 8.2.2017: missing part of the dict change
Problem:    Missing part of the dict change.
Solution:   Also change the script level dict.
2020-11-19 19:01:43 +01:00
Bram Moolenaar
c6ca9f3a29 patch 8.2.2016: swap file test is a little flaky
Problem:    Swap file test is a little flaky.
Solution:   Don't set a byte to a fixed value, increment it.
2020-11-19 18:57:23 +01:00
Bram Moolenaar
2bede173a1 patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Problem:    Vim9: literal dict #{} is not like any other language.
Solution:   Support the JavaScript syntax.
2020-11-19 18:53:18 +01:00
Bram Moolenaar
ee8b787bcd patch 8.2.2014: using CTRL-O in a prompt buffer moves cursor to start
Problem:    Using CTRL-O in a prompt buffer moves cursor to start of the line.
Solution:   Do not move the cursor when restarting edit. (closes #7330)
2020-11-19 18:46:25 +01:00
Bram Moolenaar
79cdf80bed patch 8.2.2013: Vim9: not skipping white space after unary minus
Problem:    Vim9: not skipping white space after unary minus.
Solution:   Skip whitespace. (closes #7324)
2020-11-18 17:39:05 +01:00
Bram Moolenaar
d92cc130fb patch 8.2.2012: Vim9: confusing error message when using bool wrongly
Problem:    Vim9: confusing error message when using bool wrongly.
Solution:   Mention "Bool" instead of "Special". (closes #7323)
2020-11-18 17:17:15 +01:00
Bram Moolenaar
9950280d37 patch 8.2.2011: "syn sync" reports a very large number
Problem:    "syn sync" reports a very large number.
Solution:   Use "at the first line".
2020-11-18 16:53:23 +01:00
Bram Moolenaar
8e02faf4e9 patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Problem:    Vim9: compiling fails for unreachable return statement.
Solution:   Fix it. (closes #7319)
2020-11-18 16:35:02 +01:00
Bram Moolenaar
382319211a patch 8.2.2009: MS-Windows: setting $LANG in gvimext only causes problems
Problem:    MS-Windows: setting $LANG in gvimext only causes problems.
Solution:   Do not set $LANG. (Ken Takata, closes #7325)
2020-11-18 15:30:09 +01:00
Bram Moolenaar
032f40afb8 patch 8.2.2008: MS-Windows GUI: handling channel messages lags
Problem:    MS-Windows GUI: handling channel messages lags.
Solution:   Reduce the wait time from 100 to 10 msec. (closes #7097)
2020-11-18 15:21:50 +01:00
Bram Moolenaar
17ab28daa0 patch 8.2.2007: test for insert mode in popup is not reliable
Problem:    Test for insert mode in popup is not reliable.
Solution:   Wait for the popup to disappear. (Ozaki Kiichi, closes #7321)
2020-11-18 12:24:01 +01:00
Bram Moolenaar
88774a30c0 patch 8.2.2006: .pbtxt files are not recognized
Problem:    .pbtxt files are not recognized.
Solution:   Recognize .pbtxt as protobuf text buffers. (closes #7326)
2020-11-18 12:12:39 +01:00
Bram Moolenaar
c77534c303 patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Problem:    Redoing a mapping with <Cmd> doesn't work properly.
Solution:   Fill the redo buffer.  Use "<SNR>" instead of a key code.
            (closes #7282)
2020-11-18 11:34:37 +01:00
Bram Moolenaar
b3a01946b3 patch 8.2.2004: compiler warning for uninitialized variable
Problem:    Compiler warning for uninitialized variable.
Solution:   Initialize "ufunc". (John Marriott)
2020-11-17 19:56:09 +01:00
Bram Moolenaar
1efefda623 patch 8.2.2003: build error with +conceal but without +popupwin
Problem:    Build error with +conceal but without +popupwin.
Solution:   Add #ifdef. (Tom Ryder, closes #7316)
2020-11-17 19:22:06 +01:00
Bram Moolenaar
52bf81c2d5 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Problem:    Vim9: lambda argument shadowed by function name.
Solution:   Let function name be shadowed by lambda argument. (closes #7313)
2020-11-17 18:50:44 +01:00
Bram Moolenaar
0ba48e8c27 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Problem:    Vim9: :def function does not apply 'maxfuncdepth'.
Solution:   Use 'maxfuncdepth'. (issue #7313)
2020-11-17 18:23:19 +01:00
33 changed files with 503 additions and 172 deletions

View File

@@ -112,8 +112,7 @@ In Vi # is a command to list text with numbers. In Vim9 script you can use
101 number
To improve readability there must be a space between a command and the #
that starts a comment. Note that #{ is the start of a dictionary, therefore
it does not start a comment.
that starts a comment.
Vim9 functions ~
@@ -303,8 +302,7 @@ identifier or can't be an Ex command. Examples: >
myList->add(123)
g:myList->add(123)
[1, 2, 3]->Process()
#{a: 1, b: 2}->Process()
{'a': 1, 'b': 2}->Process()
{a: 1, b: 2}->Process()
"foobar"->Process()
("foobar")->Process()
'foobar'->Process()
@@ -346,7 +344,7 @@ those cases there is no need to prefix the line with a backslash
'two',
]
And when a dict spans multiple lines: >
var mydict = #{
var mydict = {
one: 1,
two: 2,
}
@@ -430,6 +428,27 @@ No curly braces expansion ~
|curly-braces-names| cannot be used.
Dictionary literals ~
Traditionally Vim has supported dictionary literals with a {} syntax: >
let dict = {'key': value}
Later it became clear that using a simple key name is very common, thus
literally dictionaries were introduced in a backwards compatible way: >
let dict = #{key: value}
However, this #{} syntax is unlike any existing language. As it appears that
using a literaly key is much more common than using an expression, and
considering that JavaScript uses this syntax, using the {} form for dictionary
literals was considered a much more useful syntax. In Vim9 script the {} form
uses literal keys: >
let dict = {key: value}
In case an expression needs to be used for the key, square brackets can be
used, just like in JavaScript: >
let dict = {["key" .. nr]: value}
No :xit, :t, :append, :change or :insert ~
These commands are too easily confused with local variable names.

View File

@@ -1305,6 +1305,7 @@ au BufNewFile,BufRead *.pml setf promela
" Google protocol buffers
au BufNewFile,BufRead *.proto setf proto
au BufNewFile,BufRead *.pbtxt setf pbtxt
" Protocols
au BufNewFile,BufRead */etc/protocols setf protocols

View File

@@ -161,7 +161,6 @@ static char *null_libintl_bindtextdomain(const char *, const char *);
static int dyn_libintl_init(char *dir);
static void dyn_libintl_end(void);
static wchar_t *oldenv = NULL;
static HINSTANCE hLibintlDLL = 0;
static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
@@ -205,17 +204,17 @@ dyn_libintl_init(char *dir)
if (buf != NULL && buf2 != NULL)
{
GetEnvironmentVariableW(L"PATH", buf, len);
#ifdef _WIN64
# ifdef _WIN64
_snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf);
#else
# else
_snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf);
#endif
# endif
SetEnvironmentVariableW(L"PATH", buf2);
hLibintlDLL = LoadLibrary(GETTEXT_DLL);
#ifdef GETTEXT_DLL_ALT
# ifdef GETTEXT_DLL_ALT
if (!hLibintlDLL)
hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT);
#endif
# endif
SetEnvironmentVariableW(L"PATH", buf);
}
free(buf);
@@ -273,56 +272,7 @@ null_libintl_textdomain(const char* /* domainname */)
dyn_gettext_load(void)
{
char szBuff[BUFSIZE];
char szLang[BUFSIZE];
DWORD len;
HKEY keyhandle;
int gotlang = 0;
strcpy(szLang, "LANG=");
// First try getting the language from the registry, this can be
// used to overrule the system language.
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
KEY_READ, &keyhandle) == ERROR_SUCCESS)
{
len = BUFSIZE;
if (RegQueryValueEx(keyhandle, "lang", 0, NULL, (BYTE*)szBuff, &len)
== ERROR_SUCCESS)
{
szBuff[len] = 0;
strcat(szLang, szBuff);
gotlang = 1;
}
RegCloseKey(keyhandle);
}
if (!gotlang && getenv("LANG") == NULL)
{
// Get the language from the system.
// Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
// LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
// only the first two.
len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
(LPTSTR)szBuff, BUFSIZE);
if (len >= 2 && _strnicmp(szBuff, "en", 2) != 0)
{
// There are a few exceptions (probably more)
if (_strnicmp(szBuff, "cht", 3) == 0
|| _strnicmp(szBuff, "zht", 3) == 0)
strcpy(szBuff, "zh_TW");
else if (_strnicmp(szBuff, "chs", 3) == 0
|| _strnicmp(szBuff, "zhc", 3) == 0)
strcpy(szBuff, "zh_CN");
else if (_strnicmp(szBuff, "jp", 2) == 0)
strcpy(szBuff, "ja");
else
szBuff[2] = 0; // truncate to two-letter code
strcat(szLang, szBuff);
gotlang = 1;
}
}
if (gotlang)
putenv(szLang);
// Try to locate the runtime files. The path is used to find libintl.dll
// and the vim.mo files.
@@ -378,10 +328,8 @@ DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
inc_cRefThisDLL()
{
#ifdef FEAT_GETTEXT
if (g_cRefThisDll == 0) {
if (g_cRefThisDll == 0)
dyn_gettext_load();
oldenv = GetEnvironmentStringsW();
}
#endif
InterlockedIncrement((LPLONG)&g_cRefThisDll);
}
@@ -390,13 +338,8 @@ inc_cRefThisDLL()
dec_cRefThisDLL()
{
#ifdef FEAT_GETTEXT
if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0) {
if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0)
dyn_gettext_free();
if (oldenv != NULL) {
FreeEnvironmentStringsW(oldenv);
oldenv = NULL;
}
}
#else
InterlockedDecrement((LPLONG)&g_cRefThisDll);
#endif
@@ -967,8 +910,8 @@ STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
oldenv, // Use unmodified environment block.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi) // Pointer to PROCESS_INFORMATION structure.
@@ -1057,8 +1000,8 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
oldenv, // Use unmodified environment block.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi) // Pointer to PROCESS_INFORMATION structure.

View File

@@ -111,6 +111,7 @@ dict_free_contents(dict_T *d)
/*
* Clear hashtab "ht" and dict items it contains.
* If "ht" is not freed then you should call hash_init() next!
*/
void
hashtab_free_contents(hashtab_T *ht)
@@ -850,10 +851,32 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
while (**arg != '}' && **arg != NUL)
{
if ((literal
? get_literal_key(arg, &tvkey)
: eval1(arg, &tvkey, evalarg)) == FAIL) // recursive!
goto failret;
char_u *p = to_name_end(*arg, FALSE);
if (literal || (vim9script && *p == ':'))
{
if (get_literal_key(arg, &tvkey) == FAIL)
goto failret;
}
else
{
int has_bracket = vim9script && **arg == '[';
if (has_bracket)
*arg = skipwhite(*arg + 1);
if (eval1(arg, &tvkey, evalarg) == FAIL) // recursive!
goto failret;
if (has_bracket)
{
*arg = skipwhite(*arg);
if (**arg != ']')
{
emsg(_(e_missing_matching_bracket_after_dict_key));
return FAIL;
}
++*arg;
}
}
// the colon should come right after the key, but this wasn't checked
// previously, so only require it in Vim9 script.

View File

@@ -2446,16 +2446,18 @@ win_line(
&& conceal_cursor_line(wp)
&& (int)wp->w_virtcol <= vcol + n_skip)
{
# ifdef FEAT_RIGHTLEFT
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
wp->w_wcol = wp->w_width - col + boguscols - 1;
else
# endif
# endif
wp->w_wcol = col - boguscols;
wp->w_wrow = row;
did_wcol = TRUE;
curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
# ifdef FEAT_PROP_POPUP
curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
# endif
}
#endif

View File

@@ -301,3 +301,7 @@ EXTERN char e_cmd_mapping_must_end_with_cr_before_second_cmd[]
INIT(=N_("E1136: <Cmd> mapping must end with <CR> before second <Cmd>"));
EXTERN char e_cmd_maping_must_not_include_str_key[]
INIT(= N_("E1137: <Cmd> mapping must not include %s key"));
EXTERN char e_using_bool_as_number[]
INIT(= N_("E1138: Using a Bool as a Number"));
EXTERN char e_missing_matching_bracket_after_dict_key[]
INIT(= N_("E1139: Missing matching bracket after dict key"));

View File

@@ -2628,7 +2628,28 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
return ret;
// Search in parent scope for lambda
return find_var_in_scoped_ht(name, no_autoload || htp != NULL);
ret = find_var_in_scoped_ht(name, no_autoload || htp != NULL);
if (ret != NULL)
return ret;
// in Vim9 script items without a scope can be script-local
if (in_vim9script() && name[0] != NUL && name[1] != ':')
{
ht = get_script_local_ht();
if (ht != NULL)
{
ret = find_var_in_ht(ht, *name, varname,
no_autoload || htp != NULL);
if (ret != NULL)
{
if (htp != NULL)
*htp = ht;
return ret;
}
}
}
return NULL;
}
/*

View File

@@ -747,6 +747,9 @@ do_cmdline(
* cancel the whole command line, and any if/endif or loop.
* If force_abort is set, we cancel everything.
*/
#ifdef FEAT_EVAL
did_emsg_cumul += did_emsg;
#endif
did_emsg = FALSE;
/*
@@ -778,7 +781,12 @@ do_cmdline(
&& !(getline_is_func && func_has_abort(real_cookie))
#endif
)
{
#ifdef FEAT_EVAL
did_emsg_cumul += did_emsg;
#endif
did_emsg = FALSE;
}
/*
* 1. If repeating a line in a loop, get a line from lines_ga.
@@ -1026,7 +1034,10 @@ do_cmdline(
if (did_emsg && !force_abort
&& getline_equal(fgetline, cookie, get_func_line)
&& !func_has_abort(real_cookie))
{
// did_emsg_cumul is not set here
did_emsg = FALSE;
}
if (cstack.cs_looplevel > 0)
{
@@ -3471,6 +3482,11 @@ find_ex_command(
break;
}
// Not not recognize ":*" as the star command unless '*' is in
// 'cpoptions'.
if (eap->cmdidx == CMD_star && vim_strchr(p_cpo, CPO_STAR) == NULL)
p = eap->cmd;
// Look for a user defined command as a last resort. Let ":Print" be
// overruled by a user defined command.
if ((eap->cmdidx == CMD_SIZE || eap->cmdidx == CMD_Print)

View File

@@ -3691,11 +3691,7 @@ getcmdkeycmd(
else if (IS_SPECIAL(c1))
{
if (c1 == K_SNR)
{
ga_append(&line_ga, (char)K_SPECIAL);
ga_append(&line_ga, (char)KS_EXTRA);
ga_append(&line_ga, (char)KE_SNR);
}
ga_concat(&line_ga, (char_u *)"<SNR>");
else
{
semsg(e_cmd_maping_must_not_include_str_key,

View File

@@ -230,6 +230,8 @@ EXTERN int did_endif INIT(= FALSE); // just had ":endif"
EXTERN int did_emsg; // set by emsg() when the message
// is displayed or thrown
#ifdef FEAT_EVAL
EXTERN int did_emsg_cumul; // cumulative did_emsg, increased
// when did_emsg is reset.
EXTERN int called_vim_beep; // set if vim_beep() is called
EXTERN int did_uncaught_emsg; // emsg() was called and did not
// cause an exception

View File

@@ -2134,7 +2134,10 @@ gui_mch_wait_for_chars(int wtime)
break;
}
else if (input_available()
|| MsgWaitForMultipleObjects(0, NULL, FALSE, 100,
// TODO: The 10 msec is a compromise between laggy response
// and consuming more CPU time. Better would be to handle
// channel messages when they arrive.
|| MsgWaitForMultipleObjects(0, NULL, FALSE, 10,
QS_ALLINPUT) != WAIT_TIMEOUT)
break;
}
@@ -8458,7 +8461,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
TOOLINFOW *pti;
int ToolInfoSize;
if (multiline_balloon_available() == TRUE)
if (multiline_balloon_available())
ToolInfoSize = sizeof(TOOLINFOW_NEW);
else
ToolInfoSize = sizeof(TOOLINFOW);
@@ -8481,7 +8484,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
pti->hinst = 0; // Don't use string resources
pti->uId = ID_BEVAL_TOOLTIP;
if (multiline_balloon_available() == TRUE)
if (multiline_balloon_available())
{
RECT rect;
TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti;

View File

@@ -1628,7 +1628,7 @@ init_prompt(int cmdchar_todo)
if (cmdchar_todo == 'A')
coladvance((colnr_T)MAXCOL);
if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt))
if (curwin->w_cursor.col < (int)STRLEN(prompt))
curwin->w_cursor.col = (int)STRLEN(prompt);
// Make sure the cursor is in a valid position.
check_cursor();

View File

@@ -3465,8 +3465,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
if ((redo_yank || oap->op_type != OP_YANK)
&& ((!VIsual_active || oap->motion_force)
// Also redo Operator-pending Visual mode mappings
|| (VIsual_active && cap->cmdchar == ':'
&& oap->op_type != OP_COLON))
|| (VIsual_active
&& (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
&& oap->op_type != OP_COLON))
&& cap->cmdchar != 'D'
#ifdef FEAT_FOLDING
&& oap->op_type != OP_FOLD
@@ -3688,7 +3689,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
get_op_char(oap->op_type),
get_extra_op_char(oap->op_type),
oap->motion_force, cap->cmdchar, cap->nchar);
else if (cap->cmdchar != ':')
else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND)
{
int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;

View File

@@ -14,6 +14,10 @@ ufunc_T *find_func(char_u *name, int is_global, cctx_T *cctx);
int func_is_global(ufunc_T *ufunc);
int func_name_refcount(char_u *name);
void copy_func(char_u *lambda, char_u *global);
int funcdepth_increment(void);
void funcdepth_decrement(void);
int funcdepth_get(void);
void funcdepth_restore(int depth);
int call_user_func_check(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, funcexe_T *funcexe, dict_T *selfdict);
void save_funccal(funccal_entry_T *entry);
void restore_funccal(void);

View File

@@ -8,6 +8,7 @@ imported_T *find_imported_in_script(char_u *name, size_t len, int sid);
int vim9_comment_start(char_u *p);
char_u *peek_next_line_from_context(cctx_T *cctx);
char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
char_u *to_name_end(char_u *arg, int use_namespace);
char_u *to_name_const_end(char_u *arg);
exptype_T get_compare_type(char_u *p, int *len, int *type_is);
void error_white_both(char_u *op, int len);

View File

@@ -3869,9 +3869,14 @@ syn_cmd_list(
msg_puts(_("no syncing"));
else
{
msg_puts(_("syncing starts "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
msg_puts(_(" lines before top line"));
if (curwin->w_s->b_syn_sync_minlines == MAXLNUM)
msg_puts(_("syncing starts at the first line"));
else
{
msg_puts(_("syncing starts "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
msg_puts(_(" lines before top line"));
}
syn_match_msg();
}
return;
@@ -3935,19 +3940,24 @@ syn_lines_msg(void)
|| curwin->w_s->b_syn_sync_minlines > 0)
{
msg_puts("; ");
if (curwin->w_s->b_syn_sync_minlines > 0)
if (curwin->w_s->b_syn_sync_minlines == MAXLNUM)
msg_puts(_("from the first line"));
else
{
msg_puts(_("minimal "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
if (curwin->w_s->b_syn_sync_maxlines)
msg_puts(", ");
if (curwin->w_s->b_syn_sync_minlines > 0)
{
msg_puts(_("minimal "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
if (curwin->w_s->b_syn_sync_maxlines)
msg_puts(", ");
}
if (curwin->w_s->b_syn_sync_maxlines > 0)
{
msg_puts(_("maximal "));
msg_outnum(curwin->w_s->b_syn_sync_maxlines);
}
msg_puts(_(" lines before top line"));
}
if (curwin->w_s->b_syn_sync_maxlines > 0)
{
msg_puts(_("maximal "));
msg_outnum(curwin->w_s->b_syn_sync_maxlines);
}
msg_puts(_(" lines before top line"));
}
}

View File

@@ -345,6 +345,7 @@ let s:filename_checks = {
\ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'],
\ 'pascal': ['file.pas', 'file.pp', 'file.dpr', 'file.lpr'],
\ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak', '/etc/passwd', '/etc/passwd-', '/etc/passwd.edit', '/etc/shadow', '/etc/shadow-', '/etc/shadow.edit', '/var/backups/passwd.bak', '/var/backups/shadow.bak'],
\ 'pbtxt': ['file.pbtxt'],
\ 'pccts': ['file.g'],
\ 'pdf': ['file.pdf'],
\ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'],

View File

@@ -1324,4 +1324,40 @@ func Test_map_cmdkey_cmdline_mode()
%bw!
endfunc
func Test_map_cmdkey_redo()
func SelectDash()
call search('^---\n\zs', 'bcW')
norm! V
call search('\n\ze---$', 'W')
endfunc
let text =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
new Xcmdtext
call setline(1, text)
onoremap <silent> i- <Cmd>call SelectDash()<CR>
call feedkeys('2Gdi-', 'xt')
call assert_equal(['---', '---'], getline(1, 2))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---'], getline(1, 3))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---', '---'], getline(1, 4))
bwipe!
call delete('Xcmdtext')
delfunc SelectDash
ounmap i-
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -85,9 +85,12 @@ func Test_prompt_editing()
call term_sendkeys(buf, left . left . left . bs . '-')
call WaitForAssert({-> assert_equal('cmd: -hel', term_getline(buf, 1))})
call term_sendkeys(buf, "\<C-O>lz")
call WaitForAssert({-> assert_equal('cmd: -hzel', term_getline(buf, 1))})
let end = "\<End>"
call term_sendkeys(buf, end . "x")
call WaitForAssert({-> assert_equal('cmd: -helx', term_getline(buf, 1))})
call WaitForAssert({-> assert_equal('cmd: -hzelx', term_getline(buf, 1))})
call term_sendkeys(buf, "\<C-U>exit\<CR>")
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})

View File

@@ -416,8 +416,9 @@ func Test_swap_auto_delete()
" Forget about the file, recreate the swap file, then edit it again. The
" swap file should be automatically deleted.
bwipe!
" change the process ID to avoid the "still running" warning
let swapfile_bytes[24] = 0x99
" Change the process ID to avoid the "still running" warning. Must add four
" for MS-Windows to see it as a different one.
let swapfile_bytes[24] = swapfile_bytes[24] + 4
call writefile(swapfile_bytes, swapfile_name)
edit Xtest.scr
" will end up using the same swap file after deleting the existing one
@@ -433,7 +434,7 @@ func Test_swap_auto_delete()
augroup END
" change the host name
let swapfile_bytes[28 + 40] = 0x89
let swapfile_bytes[28 + 40] = swapfile_bytes[28 + 40] + 2
call writefile(swapfile_bytes, swapfile_name)
edit Xtest.scr
call assert_equal(1, filereadable(swapfile_name))

View File

@@ -316,6 +316,8 @@ func Test_syntax_arg_skipped()
syn sync ccomment
endif
call assert_notmatch('on C-style comments', execute('syntax sync'))
syn sync fromstart
call assert_match('syncing starts at the first line', execute('syntax sync'))
syn clear
endfunc
@@ -735,6 +737,7 @@ func Test_syntax_foldlevel()
redir END
call assert_equal("\nsyntax foldlevel start", @c)
syn sync fromstart
call assert_match('from the first line$', execute('syn sync'))
let a = map(range(3,9), 'foldclosed(v:val)')
call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
let a = map(range(10,15), 'foldclosed(v:val)')

View File

@@ -1266,7 +1266,7 @@ func Test_terminal_popup_insert_cmd()
call assert_equal('n', mode())
call feedkeys("\<C-D>", 'xt')
sleep 50m
call WaitFor({-> popup_list() == []})
delfunc StartTermInPopup
iunmap <F3>
endfunc

View File

@@ -226,7 +226,7 @@ enddef
def Wrong_dict_key_type(items: list<number>): list<number>
return filter(items, {_, val -> get({val: 1}, 'x')})
return filter(items, {_, val -> get({[val]: 1}, 'x')})
enddef
def Test_filter_wrong_dict_key_type()

View File

@@ -634,5 +634,19 @@ def Test_f_args()
CheckScriptSuccess(lines)
enddef
def Test_star_command()
var lines =<< trim END
vim9script
@s = 'g:success = 8'
set cpo+=*
exe '*s'
assert_equal(8, g:success)
unlet g:success
set cpo-=*
assert_fails("exe '*s'", 'E1050:')
END
CheckScriptSuccess(lines)
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -749,6 +749,9 @@ def Test_disassemble_const_expr()
enddef
def ReturnInIf(): string
if 1 < 0
return "maybe"
endif
if g:cond
return "yes"
else
@@ -759,6 +762,9 @@ enddef
def Test_disassemble_return_in_if()
var instr = execute('disassemble ReturnInIf')
assert_match('ReturnInIf\_s*' ..
'if 1 < 0\_s*' ..
' return "maybe"\_s*' ..
'endif\_s*' ..
'if g:cond\_s*' ..
'0 LOADG g:cond\_s*' ..
'1 COND2BOOL\_s*' ..

View File

@@ -1292,6 +1292,13 @@ func Test_expr5_fails()
call CheckDefFailure(["var x = 'a' .. 0z32"], 'E1105:', 1)
call CheckDefFailure(["var x = 'a' .. function('len')"], 'E1105:', 1)
call CheckDefFailure(["var x = 'a' .. function('len', ['a'])"], 'E1105:', 1)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:none'], 'E611:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:null'], 'E611:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:true'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:false'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + true'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + false'], 'E1138:', 2)
endfunc
func Test_expr5_fails_channel()
@@ -1876,6 +1883,9 @@ def Test_epxr7_funcref()
CheckDefAndScriptSuccess(lines)
enddef
let g:test_space_dict = {'': 'empty', ' ': 'space'}
let g:test_hash_dict = #{one: 1, two: 2}
def Test_expr7_dict()
# dictionary
var lines =<< trim END
@@ -1884,17 +1894,17 @@ def Test_expr7_dict()
assert_equal(g:dict_one, {'one': 1})
var key = 'one'
var val = 1
assert_equal(g:dict_one, {key: val})
assert_equal(g:dict_one, {[key]: val})
var numbers: dict<number> = #{a: 1, b: 2, c: 3}
var numbers: dict<number> = {a: 1, b: 2, c: 3}
numbers = #{a: 1}
numbers = #{}
var strings: dict<string> = #{a: 'a', b: 'b', c: 'c'}
var strings: dict<string> = {a: 'a', b: 'b', c: 'c'}
strings = #{a: 'x'}
strings = #{}
var mixed: dict<any> = #{a: 'a', b: 42}
var mixed: dict<any> = {a: 'a', b: 42}
mixed = #{a: 'x'}
mixed = #{a: 234}
mixed = #{}
@@ -1908,6 +1918,9 @@ def Test_expr7_dict()
dictdict = #{one: #{}, two: #{}}
assert_equal({'': 0}, {matchstr('string', 'wont match'): 0})
assert_equal(g:test_space_dict, {['']: 'empty', [' ']: 'space'})
assert_equal(g:test_hash_dict, {one: 1, two: 2})
END
CheckDefAndScriptSuccess(lines)
@@ -1922,7 +1935,7 @@ def Test_expr7_dict()
CheckDefFailure(["var x = #{xxx: 1", "var y = 2"], 'E722:', 2)
CheckDefFailure(["var x = #{xxx: 1,"], 'E723:', 2)
CheckDefFailure(["var x = {'a': xxx}"], 'E1001:', 1)
CheckDefFailure(["var x = {xxx: 8}"], 'E1001:', 1)
CheckDefFailure(["var x = {xx-x: 8}"], 'E1001:', 1)
CheckDefFailure(["var x = #{a: 1, a: 2}"], 'E721:', 1)
CheckDefFailure(["var x = #"], 'E1015:', 1)
CheckDefExecFailure(["var x = g:anint.member"], 'E715:', 1)
@@ -2293,12 +2306,29 @@ def Test_expr7_parens_vim9script()
CheckScriptSuccess(lines)
enddef
def Test_expr7_negate()
def Test_expr7_negate_add()
assert_equal(-99, -99)
assert_equal(-99, - 99)
assert_equal(99, --99)
assert_equal(99, -- 99)
assert_equal(99, - - 99)
assert_equal(99, +99)
assert_equal(-99, -+99)
assert_equal(-99, -+ 99)
assert_equal(-99, - +99)
assert_equal(-99, - + 99)
assert_equal(-99, +-99)
assert_equal(-99, + -99)
assert_equal(-99, + - 99)
var nr = 88
assert_equal(-88, -nr)
assert_equal(88, --nr)
assert_equal(-88, - nr)
assert_equal(-88, - +nr)
assert_equal(88, -- nr)
assert_equal(88, + nr)
assert_equal(88, --+ nr)
assert_equal(88, - - nr)
enddef
def Echo(arg: any): string

View File

@@ -49,6 +49,36 @@ def TestCompilingError()
call delete('XTest_compile_error')
enddef
def CallRecursive(n: number): number
return CallRecursive(n + 1)
enddef
def CallMapRecursive(l: list<number>): number
return map(l, {_, v -> CallMapRecursive([v])})[0]
enddef
def Test_funcdepth_error()
set maxfuncdepth=10
var caught = false
try
CallRecursive(1)
catch /E132:/
caught = true
endtry
assert_true(caught)
caught = false
try
CallMapRecursive([1])
catch /E132:/
caught = true
endtry
assert_true(caught)
set maxfuncdepth&
enddef
def ReturnString(): string
return 'string'
enddef
@@ -1426,6 +1456,15 @@ def Test_nested_lambda()
CheckScriptSuccess(lines)
enddef
def Shadowed(): list<number>
var FuncList: list<func: number> = [{ -> 42}]
return FuncList->map({_, Shadowed -> Shadowed()})
enddef
def Test_lambda_arg_shadows_func()
assert_equal([42], Shadowed())
enddef
def Line_continuation_in_def(dir: string = ''): string
var path: string = empty(dir)
\ ? 'empty'
@@ -1437,6 +1476,15 @@ def Test_line_continuation_in_def()
Line_continuation_in_def('.')->assert_equal('full')
enddef
def Test_script_var_in_lambda()
var lines =<< trim END
vim9script
var script = 'test'
assert_equal(['test'], map(['one'], {-> script}))
END
CheckScriptSuccess(lines)
enddef
def Line_continuation_in_lambda(): list<string>
var x = range(97, 100)
->map({_, v -> nr2char(v)
@@ -1530,7 +1578,7 @@ enddef
def TreeWalk(dir: string): list<any>
return readdir(dir)->map({_, val ->
fnamemodify(dir .. '/' .. val, ':p')->isdirectory()
? {val: TreeWalk(dir .. '/' .. val)}
? {[val]: TreeWalk(dir .. '/' .. val)}
: val
})
enddef
@@ -1656,5 +1704,19 @@ def Test_block_scoped_var()
CheckScriptSuccess(lines)
enddef
def Test_reset_did_emsg()
var lines =<< trim END
@s = 'blah'
au BufWinLeave * #
def Func()
var winid = popup_create('popup', {})
exe '*s'
popup_close(winid)
enddef
Func()
END
CheckScriptFailure(lines, 'E492:', 8)
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -416,7 +416,7 @@ def Test_try_catch()
var nd: dict<any>
try
nd = {g:anumber: 1}
nd = {[g:anumber]: 1}
catch /E1012:/
n = 266
endtry
@@ -459,7 +459,7 @@ def Test_try_catch()
assert_equal(322, n)
try
d = {'text': 1, g:astring: 2}
d = {text: 1, [g:astring]: 2}
catch /E721:/
n = 333
endtry

View File

@@ -213,7 +213,10 @@ tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
case VAR_SPECIAL:
if (!want_bool && in_vim9script())
{
emsg(_("E611: Using a Special as a Number"));
if (varp->v_type == VAR_BOOL)
emsg(_(e_using_bool_as_number));
else
emsg(_("E611: Using a Special as a Number"));
break;
}
return varp->vval.v_number == VVAL_TRUE ? 1 : 0;

View File

@@ -1373,6 +1373,50 @@ failed:
func_clear_free(fp, TRUE);
}
static int funcdepth = 0;
/*
* Increment the function call depth count.
* Return FAIL when going over 'maxfuncdepth'.
* Otherwise return OK, must call funcdepth_decrement() later!
*/
int
funcdepth_increment(void)
{
if (funcdepth >= p_mfd)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
return FAIL;
}
++funcdepth;
return OK;
}
void
funcdepth_decrement(void)
{
--funcdepth;
}
/*
* Get the current function call depth.
*/
int
funcdepth_get(void)
{
return funcdepth;
}
/*
* Restore the function call depth. This is for cases where there is no
* garantee funcdepth_decrement() can be called exactly the same number of
* times as funcdepth_increment().
*/
void
funcdepth_restore(int depth)
{
funcdepth = depth;
}
/*
* Call a user function.
@@ -1391,7 +1435,6 @@ call_user_func(
funccall_T *fc;
int save_did_emsg;
int default_arg_err = FALSE;
static int depth = 0;
dictitem_T *v;
int fixvar_idx = 0; // index in fixvar[]
int i;
@@ -1406,15 +1449,13 @@ call_user_func(
#endif
ESTACK_CHECK_DECLARATION
// If depth of calling is getting too high, don't execute the function
if (depth >= p_mfd)
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = -1;
return;
}
++depth;
line_breakcheck(); // check for CTRL-C hit
@@ -1437,7 +1478,7 @@ call_user_func(
{
// Execute the function, possibly compiling it first.
call_def_function(fp, argcount, argvars, funcexe->partial, rettv);
--depth;
funcdepth_decrement();
current_funccal = fc->caller;
free_funccal(fc);
return;
@@ -1783,8 +1824,7 @@ call_user_func(
}
did_emsg |= save_did_emsg;
--depth;
funcdepth_decrement();
cleanup_function_call(fc);
}

View File

@@ -750,6 +750,50 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2022,
/**/
2021,
/**/
2020,
/**/
2019,
/**/
2018,
/**/
2017,
/**/
2016,
/**/
2015,
/**/
2014,
/**/
2013,
/**/
2012,
/**/
2011,
/**/
2010,
/**/
2009,
/**/
2008,
/**/
2007,
/**/
2006,
/**/
2005,
/**/
2004,
/**/
2003,
/**/
2002,
/**/
2001,
/**/
2000,
/**/

View File

@@ -2626,7 +2626,7 @@ compile_call(
char_u fname_buf[FLEN_FIXED + 1];
char_u *tofree = NULL;
int error = FCERR_NONE;
ufunc_T *ufunc;
ufunc_T *ufunc = NULL;
int res = FAIL;
int is_autoload;
@@ -2712,13 +2712,19 @@ compile_call(
goto theend;
}
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
// An argument or local variable can be a function reference, this
// overrules a function name.
if (lookup_local(namebuf, varlen, cctx) == NULL
&& arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
}
}
// If the name is a variable, load it and use PCALL.
@@ -2761,12 +2767,12 @@ theend:
/*
* Find the end of a variable or function name. Unlike find_name_end() this
* does not recognize magic braces.
* When "namespace" is TRUE recognize "b:", "s:", etc.
* When "use_namespace" is TRUE recognize "b:", "s:", etc.
* Return a pointer to just after the name. Equal to "arg" if there is no
* valid name.
*/
static char_u *
to_name_end(char_u *arg, int namespace)
char_u *
to_name_end(char_u *arg, int use_namespace)
{
char_u *p;
@@ -2778,7 +2784,7 @@ to_name_end(char_u *arg, int namespace)
// Include a namespace such as "s:var" and "v:var". But "n:" is not
// and can be used in slice "[n:]".
if (*p == ':' && (p != arg + 1
|| !namespace
|| !use_namespace
|| vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL))
break;
return p;
@@ -2982,7 +2988,8 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
*arg = skipwhite(*arg + 1);
for (;;)
{
char_u *key = NULL;
char_u *key = NULL;
char_u *end;
if (may_get_next_line(whitep, arg, cctx) == FAIL)
{
@@ -2993,10 +3000,14 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
if (**arg == '}')
break;
if (literal)
// Eventually {name: value} will use "name" as a literal key and
// {[expr]: value} for an evaluated key.
// Temporarily: if "name" is indeed a valid key, or "[expr]" is
// used, use the new method, like JavaScript. Otherwise fall back
// to the old method.
end = to_name_end(*arg, FALSE);
if (literal || *end == ':')
{
char_u *end = to_name_end(*arg, !literal);
if (end == *arg)
{
semsg(_(e_invalid_key_str), *arg);
@@ -3009,8 +3020,11 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
}
else
{
isn_T *isn;
isn_T *isn;
int has_bracket = **arg == '[';
if (has_bracket)
*arg = skipwhite(*arg + 1);
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
@@ -3019,11 +3033,21 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal, ppconst_T *ppconst)
else
{
type_T *keytype = ((type_T **)stack->ga_data)
[stack->ga_len - 1];
[stack->ga_len - 1];
if (need_type(keytype, &t_string, -1, cctx,
FALSE, FALSE) == FAIL)
FALSE, FALSE) == FAIL)
return FAIL;
}
if (has_bracket)
{
*arg = skipwhite(*arg);
if (**arg != ']')
{
emsg(_(e_missing_matching_bracket_after_dict_key));
return FAIL;
}
++*arg;
}
}
// Check for duplicate keys, if using string keys.
@@ -3356,6 +3380,8 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
while (p > start)
{
--p;
while (VIM_ISWHITE(*p))
--p;
if (*p == '-' || *p == '+')
{
int negate = *p == '-';
@@ -4688,21 +4714,24 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (set_return_type)
cctx->ctx_ufunc->uf_ret_type = stack_type;
else
if (cctx->ctx_skip != SKIP_YES)
{
if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
&& stack_type->tt_type != VAR_VOID
&& stack_type->tt_type != VAR_UNKNOWN)
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (set_return_type)
cctx->ctx_ufunc->uf_ret_type = stack_type;
else
{
emsg(_(e_returning_value_in_function_without_return_type));
return NULL;
}
if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
&& stack_type->tt_type != VAR_VOID
&& stack_type->tt_type != VAR_UNKNOWN)
{
emsg(_(e_returning_value_in_function_without_return_type));
return NULL;
}
if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
cctx, FALSE, FALSE) == FAIL)
return NULL;
return NULL;
}
}
}
else
@@ -4719,8 +4748,7 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
// No argument, return zero.
generate_PUSHNR(cctx, 0);
}
if (generate_instr(cctx, ISN_RETURN) == NULL)
if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL)
return NULL;
// "return val | endif" is possible

View File

@@ -227,6 +227,10 @@ call_dfunc(int cdf_idx, int argcount_arg, ectx_T *ectx)
== FAIL)
return FAIL;
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
return FAIL;
// Move the vararg-list to below the missing optional arguments.
if (vararg_count > 0 && arg_to_add > 0)
*STACK_TV_BOT(arg_to_add - 1) = *STACK_TV_BOT(-1);
@@ -503,6 +507,7 @@ func_return(ectx_T *ectx)
ectx->ec_stack.ga_len = top + 1;
*STACK_TV_BOT(-1) = *STACK_TV(idx);
funcdepth_decrement();
return OK;
}
@@ -828,13 +833,14 @@ call_def_function(
int defcount = ufunc->uf_args.ga_len - argc;
sctx_T save_current_sctx = current_sctx;
int breakcheck_count = 0;
int did_emsg_before = did_emsg;
int did_emsg_before = did_emsg_cumul + did_emsg;
int save_suppress_errthrow = suppress_errthrow;
msglist_T **saved_msg_list = NULL;
msglist_T *private_msg_list = NULL;
cmdmod_T save_cmdmod;
int restore_cmdmod = FALSE;
int trylevel_at_start = trylevel;
int orig_funcdepth;
// Get pointer to item in the stack.
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
@@ -853,7 +859,7 @@ call_def_function(
|| (ufunc->uf_def_status == UF_TO_BE_COMPILED
&& compile_def_function(ufunc, FALSE, NULL) == FAIL))
{
if (did_emsg == did_emsg_before)
if (did_emsg_cumul + did_emsg == did_emsg_before)
semsg(_(e_function_is_not_compiled_str),
printable_func_name(ufunc));
return FAIL;
@@ -870,11 +876,19 @@ call_def_function(
}
}
// If depth of calling is getting too high, don't execute the function.
orig_funcdepth = funcdepth_get();
if (funcdepth_increment() == FAIL)
return FAIL;
CLEAR_FIELD(ectx);
ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
if (ga_grow(&ectx.ec_stack, 20) == FAIL)
{
funcdepth_decrement();
return FAIL;
}
ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
@@ -1072,13 +1086,10 @@ call_def_function(
// execute Ex command line
case ISN_EXEC:
{
int save_did_emsg = did_emsg;
SOURCING_LNUM = iptr->isn_lnum;
do_cmdline_cmd(iptr->isn_arg.string);
// do_cmdline_cmd() will reset did_emsg, but we want to
// keep track of the count to compare with did_emsg_before.
did_emsg += save_did_emsg;
if (did_emsg)
goto on_error;
}
break;
@@ -1197,6 +1208,8 @@ call_def_function(
{
SOURCING_LNUM = iptr->isn_lnum;
do_cmdline_cmd((char_u *)ga.ga_data);
if (did_emsg)
goto on_error;
}
else
{
@@ -2880,7 +2893,7 @@ func_return:
on_error:
// If "emsg_silent" is set then ignore the error.
if (did_emsg == did_emsg_before && emsg_silent)
if (did_emsg_cumul + did_emsg == did_emsg_before && emsg_silent)
continue;
// If we are not inside a try-catch started here, abort execution.
@@ -2938,9 +2951,10 @@ failed_early:
// Not sure if this is necessary.
suppress_errthrow = save_suppress_errthrow;
if (ret != OK && did_emsg == did_emsg_before)
if (ret != OK && did_emsg_cumul + did_emsg == did_emsg_before)
semsg(_(e_unknown_error_while_executing_str),
printable_func_name(ufunc));
funcdepth_restore(orig_funcdepth);
return ret;
}