Patch 8.2.2775

4 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 17, 2021, 12:00:00 PM4/17/21
to vim...@googlegroups.com

Patch 8.2.2775
Problem: Vim9: wrong line number used for some commands.
Solution: For :exe, :echo and the like use the line number of the start of
the command. When calling a function set the line number in the
script context.
Files: src/vim9compile.c, src/vim9execute.c, src/structs.h,
src/testdir/test_vim9_script.vim


*** ../vim-8.2.2774/src/vim9compile.c 2021-04-15 21:48:29.019181486 +0200
--- src/vim9compile.c 2021-04-17 16:51:25.508609316 +0200
***************
*** 8221,8226 ****
--- 8221,8227 ----
char_u *p = arg;
char_u *prev = arg;
int count = 0;
+ int start_ctx_lnum = cctx->ctx_lnum;

for (;;)
{
***************
*** 8235,8240 ****
--- 8236,8246 ----

if (count > 0)
{
+ long save_lnum = cctx->ctx_lnum;
+
+ // Use the line number where the command started.
+ cctx->ctx_lnum = start_ctx_lnum;
+
if (cmdidx == CMD_echo || cmdidx == CMD_echon)
generate_ECHO(cctx, cmdidx == CMD_echo, count);
else if (cmdidx == CMD_execute)
***************
*** 8243,8248 ****
--- 8249,8256 ----
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
else
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
+
+ cctx->ctx_lnum = save_lnum;
}
return p;
}
*** ../vim-8.2.2774/src/vim9execute.c 2021-04-14 21:30:02.927966474 +0200
--- src/vim9execute.c 2021-04-17 17:47:17.369735596 +0200
***************
*** 329,337 ****
if (entry != NULL)
{
// Set the script context to the script where the function was defined.
! // TODO: save more than the SID?
! entry->es_save_sid = current_sctx.sc_sid;
! current_sctx.sc_sid = ufunc->uf_script_ctx.sc_sid;
}

// Start execution at the first instruction.
--- 329,337 ----
if (entry != NULL)
{
// Set the script context to the script where the function was defined.
! // Save the current context so it can be restored on return.
! entry->es_save_sctx = current_sctx;
! current_sctx = ufunc->uf_script_ctx;
}

// Start execution at the first instruction.
***************
*** 562,568 ****
// execution context goes one level up
entry = estack_pop();
if (entry != NULL)
! current_sctx.sc_sid = entry->es_save_sid;

if (handle_closure_in_use(ectx, TRUE) == FAIL)
return FAIL;
--- 562,568 ----
// execution context goes one level up
entry = estack_pop();
if (entry != NULL)
! current_sctx = entry->es_save_sctx;

if (handle_closure_in_use(ectx, TRUE) == FAIL)
return FAIL;
*** ../vim-8.2.2774/src/structs.h 2021-04-10 13:33:44.441064014 +0200
--- src/structs.h 2021-04-17 17:45:25.093998126 +0200
***************
*** 2045,2051 ****
except_T *except; // exception info
} es_info;
#if defined(FEAT_EVAL)
! scid_T es_save_sid; // saved sc_sid when calling function
#endif
} estack_T;

--- 2045,2051 ----
except_T *except; // exception info
} es_info;
#if defined(FEAT_EVAL)
! sctx_T es_save_sctx; // saved current_sctx when calling function
#endif
} estack_T;

*** ../vim-8.2.2774/src/testdir/test_vim9_script.vim 2021-04-17 16:38:46.630960861 +0200
--- src/testdir/test_vim9_script.vim 2021-04-17 17:57:20.112165845 +0200
***************
*** 3848,3853 ****
--- 3848,3884 ----
CheckScriptFailure(['vim9script'] + lines, 'E1100:')
enddef

+ def Test_mapping_line_number()
+ var lines =<< trim END
+ vim9script
+ def g:FuncA()
+ # Some comment
+ FuncB(0)
+ enddef
+ # Some comment
+ def FuncB(
+ # Some comment
+ n: number
+ )
+ exe 'nno '
+ # Some comment
+ .. '<F3> a'
+ .. 'b'
+ .. 'c'
+ enddef
+ END
+ CheckScriptSuccess(lines)
+ var res = execute('verbose nmap <F3>')
+ assert_match('No mapping found', res)
+
+ g:FuncA()
+ res = execute('verbose nmap <F3>')
+ assert_match(' <F3> .* abc.*Last set from .*XScriptSuccess\d\+ line 11', res)
+
+ nunmap <F3>
+ delfunc g:FuncA
+ enddef
+
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new
*** ../vim-8.2.2774/src/version.c 2021-04-17 16:38:46.634960849 +0200
--- src/version.c 2021-04-17 17:44:04.018178309 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2775,
/**/

--
hundred-and-one symptoms of being an internet addict:
114. You are counting items, you go "0,1,2,3,4,5,6,7,8,9,A,B,C,D...".

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages