diff src/vim9execute.c @ 21969:ba2415df82d7 v8.2.1534

patch 8.2.1534: Vim9: type error for argument type is not at call position Commit: https://github.com/vim/vim/commit/ee8580e52e767916e2a95e8ac0732fd8a5ae0651 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 28 17:19:07 2020 +0200 patch 8.2.1534: Vim9: type error for argument type is not at call position Problem: Vim9: type error for argument type is not at call position. Solution: Set the context and stack after checking the arguments. (issue #6785)
author Bram Moolenaar <Bram@vim.org>
date Fri, 28 Aug 2020 17:30:04 +0200
parents 5edd776d886d
children 3fe594c72d8c
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -726,7 +726,7 @@ call_def_function(
     int		idx;
     int		ret = FAIL;
     int		defcount = ufunc->uf_args.ga_len - argc;
-    int		save_sc_version = current_sctx.sc_version;
+    sctx_T	save_current_sctx = current_sctx;
     int		breakcheck_count = 0;
     int		called_emsg_before = called_emsg;
 
@@ -867,7 +867,10 @@ call_def_function(
 	ectx.ec_instr = dfunc->df_instr;
     }
 
+    // Following errors are in the function, not the caller.
     // Commands behave like vim9script.
+    estack_push_ufunc(ufunc, 1);
+    current_sctx = ufunc->uf_script_ctx;
     current_sctx.sc_version = SCRIPT_VERSION_VIM9;
 
     // Decide where to start execution, handles optional arguments.
@@ -2614,9 +2617,11 @@ failed:
     // When failed need to unwind the call stack.
     while (ectx.ec_frame_idx != initial_frame_idx)
 	func_return(&ectx);
+
+    estack_pop();
+    current_sctx = save_current_sctx;
+
 failed_early:
-    current_sctx.sc_version = save_sc_version;
-
     // Free all local variables, but not arguments.
     for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
 	clear_tv(STACK_TV(idx));