patch 9.2.0301: Vim9: void function return value inconsistent

Commit: 
https://github.com/vim/vim/commit/f07a1ed9031333de79abeee5b6b19a895dc72c73
Author: Hirohito Higashi <[email protected]>
Date:   Sun Apr 5 16:17:58 2026 +0000

    patch 9.2.0301: Vim9: void function return value inconsistent
    
    Problem:  Vim9: void function return value inconsistent between
              script and :def
    Solution: Make void built-in functions like bufload() return void
              consistently (Hirohito Higashi)
    
    In Vim9 script, calling a void built-in function (e.g. bufload()) at the
    script level did not set rettv to VAR_VOID, making it appear to return
    0. Inside :def it correctly returned VAR_VOID and raised E1031.  Set
    rettv to VAR_VOID after calling a ret_void built-in function in Vim9
    script so the behavior is consistent.
    
    Also fix the documentation for bufload() and ch_logfile() to correctly
    state that the return type is void.
    
    closes: #19919
    
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: Yegappan Lakshmanan <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 30894b96d..cdf8203ab 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1,4 +1,4 @@
-*builtin.txt*  For Vim version 9.2.  Last change: 2026 Mar 25
+*builtin.txt*  For Vim version 9.2.  Last change: 2026 Apr 05
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -82,7 +82,7 @@ browsedir({title}, {initdir}) String  put up a directory 
requester
 bufadd({name})                 Number  add a buffer to the buffer list
 bufexists({buf})               Number  |TRUE| if buffer {buf} exists
 buflisted({buf})               Number  |TRUE| if buffer {buf} is listed
-bufload({buf})                 Number  load buffer {buf} if not loaded yet
+bufload({buf})                 none    load buffer {buf} if not loaded yet
 bufloaded({buf})               Number  |TRUE| if buffer {buf} is loaded
 bufname([{buf}])               String  name of the buffer {buf}
 bufnr([{buf} [, {create}]])    Number  number of the buffer {buf}
@@ -1500,7 +1500,7 @@ bufload({buf})                                            
*bufload()*
                Can also be used as a |method|: >
                        eval 'somename'->bufload()
 <
-               Return type: |Number|
+               Return type: void
 
 
 bufloaded({buf})                                       *bufloaded()*
diff --git a/runtime/doc/channel.txt b/runtime/doc/channel.txt
index 7ad10fa0c..f0b4f57c2 100644
--- a/runtime/doc/channel.txt
+++ b/runtime/doc/channel.txt
@@ -1,4 +1,4 @@
-*channel.txt*  For Vim version 9.2.  Last change: 2026 Mar 13
+*channel.txt*  For Vim version 9.2.  Last change: 2026 Apr 05
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -736,7 +736,7 @@ ch_logfile({fname} [, {mode}])                              
        *ch_logfile()*
                Can also be used as a |method|: >
                        'logfile'->ch_logfile('w')
 <
-               Return type: |Number|
+               Return type: void
 
 ch_open({address} [, {options}])                               *ch_open()*
                Open a channel to {address}.  See |channel|.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f026b384e..42f580db5 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -3499,6 +3499,8 @@ call_internal_func(
        return FCERR_OTHER;
     argvars[argcount].v_type = VAR_UNKNOWN;
     global_functions[i].f_func(argvars, rettv);
+    if (in_vim9script() && global_functions[i].f_retfunc == ret_void)
+       rettv->v_type = VAR_VOID;
     return FCERR_NONE;
 }
 
@@ -3509,6 +3511,8 @@ call_internal_func_by_idx(
        typval_T    *rettv)
 {
     global_functions[idx].f_func(argvars, rettv);
+    if (in_vim9script() && global_functions[idx].f_retfunc == ret_void)
+       rettv->v_type = VAR_VOID;
 }
 
 /*
diff --git a/src/testdir/test_vim9_builtin.vim 
b/src/testdir/test_vim9_builtin.vim
index d8f69eff3..b74f324ae 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -4089,8 +4089,8 @@ enddef
 
 def Test_setenv()
   v9.CheckSourceDefAndScriptFailure(['setenv(1, 2)'], ['E1013: Argument 1: 
type mismatch, expected string but got number', 'E1174: String required for 
argument 1'])
-  assert_equal(0, setenv('', ''))
-  assert_equal(0, setenv('', v:null))
+  setenv('', '')
+  setenv('', v:null)
 enddef
 
 def Test_setfperm()
@@ -4939,7 +4939,7 @@ enddef
 
 def Test_timer_stop()
   v9.CheckSourceDefAndScriptFailure(['timer_stop("x")'], ['E1013: Argument 1: 
type mismatch, expected number but got string', 'E1210: Number required for 
argument 1'])
-  assert_equal(0, timer_stop(100))
+  timer_stop(100)
 enddef
 
 def Test_tolower()
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index f4cd1edaa..549145f2f 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -5002,6 +5002,41 @@ def Test_void_method_chain()
     defcompile TestFunc
   END
   v9.CheckScriptFailure(lines, 'E1031: Cannot use void value')
+
+  #### Case 4: Script-level and :def should behave the same ####
+  # script-level: void built-in assigned to variable
+  lines =<< trim END
+    vim9script
+    var x = bufload('')
+  END
+  v9.CheckScriptFailure(lines, 'E1031: Cannot use void value')
+
+  # inside def: same error
+  lines =<< trim END
+    vim9script
+    def TestFunc()
+      var x = bufload('')
+    enddef
+    TestFunc()
+  END
+  v9.CheckScriptFailure(lines, 'E1031: Cannot use void value')
+
+  # script-level: echo void built-in
+  lines =<< trim END
+    vim9script
+    echo bufload('')
+  END
+  v9.CheckScriptFailure(lines, 'E1186: Expression does not result in a value: 
bufload(')
+
+  # inside def: compile-time error
+  lines =<< trim END
+    vim9script
+    def TestFunc()
+      echo bufload('')
+    enddef
+    TestFunc()
+  END
+  v9.CheckScriptFailure(lines, 'E1186: Expression does not result in a value: 
bufload(')
 enddef
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/version.c b/src/version.c
index 4884c3b53..d25ba8f0e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    301,
 /**/
     300,
 /**/

-- 
-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1w9QMN-005WES-Kz%40256bit.org.

Raspunde prin e-mail lui