Compare commits

...

10 Commits

Author SHA1 Message Date
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
19 changed files with 196 additions and 129 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

@@ -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

@@ -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

@@ -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

@@ -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 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

@@ -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

@@ -417,7 +417,7 @@ func Test_swap_auto_delete()
" swap file should be automatically deleted.
bwipe!
" change the process ID to avoid the "still running" warning
let swapfile_bytes[24] = 0x99
let swapfile_bytes[24] = swapfile_bytes[24] + 1
call writefile(swapfile_bytes, swapfile_name)
edit Xtest.scr
" will end up using the same swap file after deleting the existing one
@@ -433,7 +433,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

@@ -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

@@ -1569,7 +1569,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

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

@@ -750,6 +750,26 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2016,
/**/
2015,
/**/
2014,
/**/
2013,
/**/
2012,
/**/
2011,
/**/
2010,
/**/
2009,
/**/
2008,
/**/
2007,
/**/
2006,
/**/

View File

@@ -2771,7 +2771,7 @@ theend:
* Return a pointer to just after the name. Equal to "arg" if there is no
* valid name.
*/
static char_u *
char_u *
to_name_end(char_u *arg, int namespace)
{
char_u *p;
@@ -2988,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)
{
@@ -2999,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);
@@ -3015,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;
@@ -3025,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.
@@ -3362,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 == '-';
@@ -4694,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
@@ -4725,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