]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1791: type(void) throws an internal error v9.1.1791
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 25 Sep 2025 19:21:16 +0000 (19:21 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 25 Sep 2025 19:21:16 +0000 (19:21 +0000)
Problem:  type(void) throws an internal error (atitcreate)
Solution: Return proper error message (Yegappan Lakshmanan)

fixes: #17310
closes: #18392

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalfunc.c
src/evalvars.c
src/proto/typval.pro
src/testdir/test_vim9_script.vim
src/testdir/test_vimscript.vim
src/typval.c
src/version.c

index a8d190638bc6586581c6d91ffe32c474dea242bd..e4e0c29b28f67813a1807a0005f399c8d7f8affd 100644 (file)
@@ -12623,9 +12623,11 @@ f_type(typval_T *argvars, typval_T *rettv)
                }
                break;
            }
+       case VAR_VOID:
+           emsg(_(e_cannot_use_void_value));
+           break;
        case VAR_UNKNOWN:
        case VAR_ANY:
-       case VAR_VOID:
            internal_error_no_abort("f_type(UNKNOWN)");
            n = -1;
            break;
index e1eb89437a52fa5c8b4e4bcb24351fcc04d7b6f5..d9376530ca289cff318e3dc7c6814a4be7bca089 100644 (file)
@@ -3359,7 +3359,7 @@ eval_variable(
                    }
                }
            }
-           copy_tv(tv, rettv);
+           ret = copy_tv(tv, rettv);
        }
     }
 
index 2080a262c65f2eb02ac962815a13b7f2f987560d..fcd9cd1c4cfe8d64dcb4148a5cda61206662de91 100644 (file)
@@ -66,7 +66,7 @@ char_u *tv_get_string_buf_chk(typval_T *varp, char_u *buf);
 char_u *tv_get_string_buf_chk_strict(typval_T *varp, char_u *buf, int strict);
 char_u *tv_stringify(typval_T *varp, char_u *buf);
 int tv_check_lock(typval_T *tv, char_u *name, int use_gettext);
-void copy_tv(typval_T *from, typval_T *to);
+int copy_tv(typval_T *from, typval_T *to);
 int typval_compare2(typval_T *tv1, typval_T *tv2, exprtype_T type, int ic, int *res);
 int typval_compare(typval_T *tv1, typval_T *tv2, exprtype_T type, int ic);
 int typval_compare_list(typval_T *tv1, typval_T *tv2, exprtype_T type, int ic, int *res);
index 823a6cf2599c7de8f8afb4502372e0a0a9407f69..3c2c0cc07ccca3526e20a37440201605f3b0ef18 100644 (file)
@@ -5580,6 +5580,17 @@ def Test_multikey_dict_in_block()
   unlet g:TestDict
 enddef
 
+" Test for using the type() function with void
+def Test_type_func_with_void()
+  var lines =<< trim END
+    vim9script
+    def GetVoidValue(): void
+    enddef
+    echo type(GetVoidValue())
+  END
+  v9.CheckSourceFailure(lines, 'E1031: Cannot use void value', 4)
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
index bf5a875f168980deb56e4d171f938d96a66de189..0be53dc5a36235235064f6863b3cb4b26b55941c 100644 (file)
@@ -6522,7 +6522,7 @@ func Test_type()
     endif
     call assert_equal(v:t_blob, type(test_null_blob()))
 
-    call assert_fails("call type(test_void())", ['E340:', 'E685:'])
+    call assert_fails("call type(test_void())", ['E1031: Cannot use void value', 'E1031: Cannot use void value'])
     call assert_fails("call type(test_unknown())", ['E340:', 'E685:'])
 
     call assert_equal(0, 0 + v:false)
@@ -6599,6 +6599,10 @@ func Test_type()
     call assert_true(empty(v:null))
     call assert_true(empty(v:none))
 
+    def s:GetVoidValue(): void
+    enddef
+    call assert_fails('let x = type(s:GetVoidValue())', 'E1031: Cannot use void value')
+
     func ChangeYourMind()
        try
            return v:true
index b4ee7ec63f499575fb64179c214dd7d59fb161f6..7dc3e86731c9cd40d0fd02911990e3b9cd025dd3 100644 (file)
@@ -1357,9 +1357,11 @@ tv_check_lock(typval_T *tv, char_u *name, int use_gettext)
  * It is OK for "from" and "to" to point to the same item.  This is used to
  * make a copy later.
  */
-    void
+    int
 copy_tv(typval_T *from, typval_T *to)
 {
+    int                ret = OK;
+
     to->v_type = from->v_type;
     to->v_lock = 0;
     switch (from->v_type)
@@ -1465,12 +1467,16 @@ copy_tv(typval_T *from, typval_T *to)
            break;
        case VAR_VOID:
            emsg(_(e_cannot_use_void_value));
+           ret = FAIL;
            break;
        case VAR_UNKNOWN:
        case VAR_ANY:
            internal_error_no_abort("copy_tv(UNKNOWN)");
+           ret = FAIL;
            break;
     }
+
+    return ret;
 }
 
 /*
index daf0d5f9727f9c6cd6428769e7e6bd7231b66bd4..f48b3d79e6aff7a215023313de382346f9f7ee00 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1791,
 /**/
     1790,
 /**/