Skip to content

Commit 49f1e9e

Browse files
committed
patch 8.2.2645: using inline function is not properly tested
Problem: Using inline function is not properly tested. Solution: Add test cases, esp. for errors. Minor code improvements.
1 parent da1dbed commit 49f1e9e

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,5 @@ EXTERN char e_missing_end_block[]
381381
INIT(= N_("E1171: Missing } after inline function"));
382382
EXTERN char e_cannot_use_default_values_in_lambda[]
383383
INIT(= N_("E1172: Cannot use default values in a lambda"));
384+
EXTERN char e_text_found_after_enddef_str[]
385+
INIT(= N_("E1173: Text found after enddef: %s"));

src/testdir/test_vim9_expr.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,13 +1961,46 @@ def Test_expr7_lambda_block()
19611961
return 'no'
19621962
})
19631963
assert_equal(['no', 'yes', 'no'], dll)
1964+
1965+
sandbox var Safe = (nr: number): number => {
1966+
return nr + 7
1967+
}
1968+
assert_equal(10, Safe(3))
19641969
END
19651970
CheckDefAndScriptSuccess(lines)
19661971

19671972
lines =<< trim END
19681973
map([1, 2], (k, v) => { redrawt })
19691974
END
19701975
CheckDefAndScriptFailure(lines, 'E488')
1976+
1977+
lines =<< trim END
1978+
var Func = (nr: int) => {
1979+
echo nr
1980+
}
1981+
END
1982+
CheckDefAndScriptFailure(lines, 'E1010', 1)
1983+
1984+
lines =<< trim END
1985+
var Func = (nr: number): int => {
1986+
return nr
1987+
}
1988+
END
1989+
CheckDefAndScriptFailure(lines, 'E1010', 1)
1990+
1991+
lines =<< trim END
1992+
var Func = (nr: number): int => {
1993+
return nr
1994+
END
1995+
CheckDefAndScriptFailure(lines, 'E1171', 1) # line nr is function start
1996+
1997+
lines =<< trim END
1998+
vim9script
1999+
var Func = (nr: number): int => {
2000+
var ll =<< ENDIT
2001+
nothing
2002+
END
2003+
CheckScriptFailure(lines, 'E1145: Missing heredoc end marker: ENDIT', 2)
19712004
enddef
19722005

19732006
def NewLambdaWithComments(): func

src/testdir/test_vim9_func.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ def Test_endfunc_enddef()
8686
enddef
8787
END
8888
CheckScriptFailure(lines, 'E1152:', 4)
89+
90+
lines =<< trim END
91+
def Ok()
92+
echo 'hello'
93+
enddef | echo 'there'
94+
def Bad()
95+
echo 'hello'
96+
enddef there
97+
END
98+
CheckScriptFailure(lines, 'E1173: Text found after enddef: there', 6)
8999
enddef
90100

91101
def Test_missing_endfunc_enddef()

src/userfunc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,16 @@ get_function_body(
731731
else if (line_arg != NULL && *skipwhite(line_arg) != NUL)
732732
nextcmd = line_arg;
733733
else if (*p != NUL && *p != (vim9_function ? '#' : '"')
734-
&& p_verbose > 0
735-
&& eap->cmdidx != CMD_block)
736-
give_warning2(eap->cmdidx == CMD_def
737-
? (char_u *)_("W1001: Text found after :enddef: %s")
738-
: (char_u *)_("W22: Text found after :endfunction: %s"),
739-
p, TRUE);
740-
if (nextcmd != NULL)
734+
&& (vim9_function || p_verbose > 0))
735+
{
736+
if (eap->cmdidx == CMD_def)
737+
semsg(_(e_text_found_after_enddef_str), p);
738+
else
739+
give_warning2((char_u *)
740+
_("W22: Text found after :endfunction: %s"),
741+
p, TRUE);
742+
}
743+
if (nextcmd != NULL && *skipwhite(nextcmd) != NUL)
741744
{
742745
// Another command follows. If the line came from "eap"
743746
// we can simply point into it, otherwise we need to

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2645,
753755
/**/
754756
2644,
755757
/**/

0 commit comments

Comments
 (0)