patch 9.0.2172: Vim9: compiling :defer may fail

Commit: 
https://github.com/vim/vim/commit/a185a31fc05c2dd15315cd59afc02b69aabb5893
Author: Yegappan Lakshmanan <yegap...@yahoo.com>
Date:   Sat Dec 16 14:36:08 2023 +0100

    patch 9.0.2172: Vim9: compiling :defer may fail
    
    Problem:  Vim9: compiling :defer may fail
    Solution: compile defer, when ctx_skip is not SKIP_YES
    
    compiling defer fails in an if statement with false condition,
    so check the ctx_skip value when compiling :defer
    
    fixes:  #13698
    closes: #13702
    
    Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index b64f05e89..2aca20ad8 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -4783,6 +4783,19 @@ def Test_multidefer_with_exception()
   v9.CheckSourceSuccess(lines)
 enddef
 
+" Test for using ":defer" inside an if statement with a false condition
+def Test_defer_skipped()
+  var lines =<< trim END
+    def Foo()
+      if false
+        defer execute('echow "hello"', "")
+      endif
+    enddef
+    defcompile
+  END
+  v9.CheckSourceSuccess(lines)
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
diff --git a/src/version.c b/src/version.c
index de90fcec5..213a0e7c2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,7 +705,7 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
-    2171,
+    2172,
 /**/
     2170,
 /**/
diff --git a/src/vim9cmds.c b/src/vim9cmds.c
index 392bab412..07e6501a9 100644
--- a/src/vim9cmds.c
+++ b/src/vim9cmds.c
@@ -2020,11 +2020,14 @@ compile_defer(char_u *arg_start, cctx_T *cctx)
     *paren = '(';
 
     // check for function type
-    type = get_type_on_stack(cctx, 0);
-    if (type->tt_type != VAR_FUNC)
+    if (cctx->ctx_skip != SKIP_YES)
     {
-       emsg(_(e_function_name_required));
-       return NULL;
+       type = get_type_on_stack(cctx, 0);
+       if (type->tt_type != VAR_FUNC)
+       {
+           emsg(_(e_function_name_required));
+           return NULL;
+       }
     }
 
     // compile the arguments
@@ -2032,24 +2035,27 @@ compile_defer(char_u *arg_start, cctx_T *cctx)
     if (compile_arguments(&arg, cctx, &argcount, CA_NOT_SPECIAL) == FAIL)
        return NULL;
 
-    if (func_idx >= 0)
+    if (cctx->ctx_skip != SKIP_YES)
     {
-       type2_T *argtypes = NULL;
-       type2_T shuffled_argtypes[MAX_FUNC_ARGS];
+       if (func_idx >= 0)
+       {
+           type2_T     *argtypes = NULL;
+           type2_T     shuffled_argtypes[MAX_FUNC_ARGS];
 
-       if (check_internal_func_args(cctx, func_idx, argcount, FALSE,
-                                        &argtypes, shuffled_argtypes) == FAIL)
+           if (check_internal_func_args(cctx, func_idx, argcount, FALSE,
+                       &argtypes, shuffled_argtypes) == FAIL)
+               return NULL;
+       }
+       else if (check_func_args_from_type(cctx, type, argcount, TRUE,
+                   arg_start) == FAIL)
            return NULL;
-    }
-    else if (check_func_args_from_type(cctx, type, argcount, TRUE,
-                                                           arg_start) == FAIL)
-       return NULL;
 
-    defer_var_idx = get_defer_var_idx(cctx);
-    if (defer_var_idx == 0)
-       return NULL;
-    if (generate_DEFER(cctx, defer_var_idx - 1, argcount) == FAIL)
-       return NULL;
+       defer_var_idx = get_defer_var_idx(cctx);
+       if (defer_var_idx == 0)
+           return NULL;
+       if (generate_DEFER(cctx, defer_var_idx - 1, argcount) == FAIL)
+           return NULL;
+    }
 
     return skipwhite(arg);
 }

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rEUyV-0054Sp-KB%40256bit.org.

Raspunde prin e-mail lui