Skip to content

Commit 673660a

Browse files
committed
patch 8.2.0150: cannot define python function when using :execute
Problem: Cannot define python function when using :execute. (Yasuhiro Matsumoto) Solution: Do not recognize "def" inside "function.
1 parent 8a7d654 commit 673660a

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/testdir/test_vim9_script.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Test various aspects of the Vim9 script language.
22

3+
source check.vim
4+
35
" Check that "lines" inside ":def" results in an "error" message.
46
func CheckDefFailure(lines, error)
57
call writefile(['def! Func()'] + a:lines + ['enddef'], 'Xdef')
@@ -355,5 +357,16 @@ def Test_fixed_size_list()
355357
call assert_equal([2, 99, 3, 4, 5], l)
356358
enddef
357359

360+
" Test that inside :function a Python function can be defined, :def is not
361+
" recognized.
362+
func Test_function_python()
363+
CheckFeature python3
364+
let py = 'python3'
365+
execute py "<< EOF"
366+
def do_something():
367+
return 1
368+
EOF
369+
endfunc
370+
358371

359372
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/userfunc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,8 +2667,11 @@ ex_function(exarg_T *eap)
26672667
indent += 2;
26682668

26692669
// Check for defining a function inside this function.
2670+
// Only recognize "def" inside "def", not inside "function",
2671+
// For backwards compatibility, see Test_function_python().
26702672
c = *p;
2671-
if (checkforcmd(&p, "function", 2) || checkforcmd(&p, "def", 3))
2673+
if (checkforcmd(&p, "function", 2)
2674+
|| (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3)))
26722675
{
26732676
if (*p == '!')
26742677
p = skipwhite(p + 1);

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
150,
745747
/**/
746748
149,
747749
/**/

0 commit comments

Comments
 (0)