Skip to content

Commit 7a6eaa0

Browse files
committed
patch 8.2.2635: Vim9: cannot define an inline function
Problem: Vim9: cannot define an inline function. Solution: Make an inline function mostly work.
1 parent f90c855 commit 7a6eaa0

7 files changed

Lines changed: 660 additions & 449 deletions

File tree

src/errors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,7 @@ EXTERN char e_import_as_name_not_supported_here[]
377377
INIT(= N_("E1169: 'import * as {name}' not supported here"));
378378
EXTERN char e_cannot_use_hash_curly_to_start_comment[]
379379
INIT(= N_("E1170: Cannot use #{ to start a comment"));
380+
EXTERN char e_missing_end_block[]
381+
INIT(= N_("E1171: Missing } after inline function"));
382+
EXTERN char e_cannot_use_default_values_in_lambda[]
383+
INIT(= N_("E1172: Cannot use default values in a lambda"));

src/misc2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,8 +2026,9 @@ ga_clear_strings(garray_T *gap)
20262026
{
20272027
int i;
20282028

2029-
for (i = 0; i < gap->ga_len; ++i)
2030-
vim_free(((char_u **)(gap->ga_data))[i]);
2029+
if (gap->ga_data != NULL)
2030+
for (i = 0; i < gap->ga_len; ++i)
2031+
vim_free(((char_u **)(gap->ga_data))[i]);
20312032
ga_clear(gap);
20322033
}
20332034

src/proto/vim9compile.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ char_u *to_name_end(char_u *arg, int use_namespace);
1414
char_u *to_name_const_end(char_u *arg);
1515
exprtype_T get_compare_type(char_u *p, int *len, int *type_is);
1616
void error_white_both(char_u *op, int len);
17+
void fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx);
1718
int assignment_len(char_u *p, int *heredoc);
1819
void vim9_declare_error(char_u *name);
1920
int check_vim9_unlet(char_u *name);

src/testdir/test_vim9_expr.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,25 @@ def Test_expr7_lambda()
19461946
CheckScriptSuccess(lines)
19471947
enddef
19481948

1949+
def Test_expr7_lambda_block()
1950+
var lines =<< trim END
1951+
var Func = (s: string): string => {
1952+
return 'hello ' .. s
1953+
}
1954+
assert_equal('hello there', Func('there'))
1955+
1956+
var ll = range(3)
1957+
var dll = mapnew(ll, (k, v): string => {
1958+
if v % 2
1959+
return 'yes'
1960+
endif
1961+
return 'no'
1962+
})
1963+
assert_equal(['no', 'yes', 'no'], dll)
1964+
END
1965+
CheckDefAndScriptSuccess(lines)
1966+
enddef
1967+
19491968
def NewLambdaWithComments(): func
19501969
return (x) =>
19511970
# some comment

0 commit comments

Comments
 (0)