patch 8.2.3005: Vim9: using a void value does not give a proper error message

Problem:    Vim9: using a void value does not give a proper error message.
Solution:   Give a clear error message. (clodes #8387)
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index f09cb1d..9d2f697 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -117,7 +117,7 @@
         '\d 2STRING stack\[-1\]\_s*' ..
         '\d\+ PUSHS ".txt"\_s*' ..
         '\d\+ EXECCONCAT 4\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -133,7 +133,7 @@
     assert_match('<SNR>\d*_PyHeredoc.*' ..
           "    python3 << EOF^@      print('hello')^@EOF\\_s*" ..
           '\d EXEC_SPLIT     python3 << EOF^@      print(''hello'')^@EOF\_s*' ..
-          '\d RETURN 0',
+          '\d RETURN void',
           res)
   enddef
 endif
@@ -153,7 +153,7 @@
         '\d SUBSTITUTE   :%s/a/\\=expr/&g#c\_s*' ..
         '    0 LOAD $0\_s*' ..
         '    -------------\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -181,7 +181,7 @@
         ' -------------\_s*' ..
         '\d BCALL searchpair(argc 5)\_s*' ..
         '\d DROP\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -209,7 +209,7 @@
         '\d REDIR END\_s*' ..
         '\d CONCAT\_s*' ..
         '\d STORE $0\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -228,7 +228,7 @@
         '\d CEXPR pre cexpr\_s*' ..
         '\d LOAD $0\_s*' ..
         '\d CEXPR core cexpr "cexpr errors"\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -244,7 +244,7 @@
         '\d EXEC   norm! m\[jjm\]\_s*' ..
         '  :''\[,''\]yank\_s*' ..
         '\d EXEC   :''\[,''\]yank\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -258,7 +258,7 @@
         ' :3put ="text"\_s*' ..
         '\d PUSHS "text"\_s*' ..
         '\d PUT = 3\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -272,7 +272,7 @@
         ' :$-2put a\_s*' ..
         '\d RANGE $-2\_s*' ..
         '\d PUT a range\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -390,7 +390,7 @@
         '\d\+ PUSHNR 1\_s*' ..
         '\d\+ LOAD $2\_s*' ..
         '\d\+ STOREINDEX blob\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -413,7 +413,7 @@
         '\d LOAD $0\_s*' ..
         '\d MEMBER dd\_s*' ..
         '\d STOREINDEX any\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -448,7 +448,7 @@
         '\d\+ STORE $1\_s*' ..
         '\d\+ SLICE 2\_s*' ..
         '\d\+ STORE $2\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -476,7 +476,7 @@
         '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
         '\d\+ LISTAPPEND\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -503,7 +503,7 @@
         '\d\+ CHECKTYPE number stack\[-1\]\_s*' ..
         '\d\+ BLOBAPPEND\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -530,7 +530,7 @@
         '\d\+ PUSHNR 2\_s*' ..
         '\d\+ BLOBSLICE\_s*' ..
         '\d\+ ECHO 1\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -720,7 +720,7 @@
         '\d LOAD arg\[-1\]\_s*' ..
         '\d CONCAT\_s*' ..
         '\d STOREOUTER level 1 $0\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 
   res = execute('disass g:Get')
@@ -754,7 +754,7 @@
         '\d PCALL top (argc 1)\_s*' ..
         '\d PCALL end\_s*' ..
         '\d DROP\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -1012,7 +1012,7 @@
         '\d PUSHS "UserFunc"\_s*' ..
         '\d BCALL funcref(argc 1)\_s*' ..
         '\d STORE $2\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         instr)
 enddef
 
@@ -1039,7 +1039,7 @@
         'var chan1: channel\_s*' ..
         '\d PUSHCHANNEL 0\_s*' ..
         '\d STORE $2\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         instr)
 enddef
 
@@ -1111,7 +1111,7 @@
         'echomsg "inner"\_s*' ..
         'enddef\_s*' ..
         '\d NEWFUNC <lambda>\d\+ Inner\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         instr)
 enddef
 
@@ -1133,7 +1133,7 @@
         '\d DEF /Info\_s*' ..
         'def /Info/\_s*' ..
         '\d DEF /Info/\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         instr)
 enddef
 
@@ -1264,7 +1264,7 @@
         'endfor\_s*' ..
         '\d\+ JUMP -> 8\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         instr)
 enddef
 
@@ -1321,7 +1321,7 @@
         'endfor\_s*' ..
         '21 JUMP -> 4\_s*' ..
         '\d\+ DROP\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         instr)
 enddef
 
@@ -1341,7 +1341,7 @@
         '\d NEWLIST size 2\_s*' ..
         '\d SETTYPE list<number>\_s*' ..
         '\d STORE $0\_s*' ..
-        '\d RETURN 0\_s*',
+        '\d RETURN void\_s*',
         instr)
 enddef
 
@@ -1828,7 +1828,7 @@
       'echo "" ?? "empty string"\_s*' ..
       '\d\+ PUSHS "empty string"\_s*' ..
       '\d\+ ECHO 1\_s*' ..
-      '\d\+ RETURN 0',
+      '\d\+ RETURN void',
       res)
 enddef
 
@@ -1855,7 +1855,7 @@
           'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '.*' ..
           '\d PUSHNR 42.*' ..
           '\d ECHO 1.*' ..
-          '\d RETURN 0',
+          '\d RETURN void',
           instr)
     else
       # condition false, function just returns
@@ -1863,7 +1863,7 @@
           'if ' .. substitute(case[0], '[[~]', '\\\0', 'g') .. '[ \n]*' ..
           'echo 42[ \n]*' ..
           'endif[ \n]*' ..
-          '\d RETURN 0',
+          '\d RETURN void',
           instr)
     endif
 
@@ -1901,7 +1901,7 @@
         '\d\+ LOAD $1\_s*' ..
         '\d\+ CONCAT\_s*' ..
         '\d\+ EXECUTE 1\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -1920,7 +1920,7 @@
         "echoerr 'went' .. 'wrong'\\_s*" ..
         '\d PUSHS "wentwrong"\_s*' ..
         '\d ECHOERR 1\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -2029,7 +2029,7 @@
         '\d SHUFFLE 2 up 1\_s*' ..
         '\d BCALL append(argc 2)\_s*' ..
         '\d DROP\_s*' ..
-        '\d RETURN 0',
+        '\d RETURN void',
         res)
 enddef
 
@@ -2052,7 +2052,7 @@
         '\d PUSHS "error"\_s*' ..
         '\d ECHOERR 1\_s*' ..
         '\d CMDMOD_REV\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -2081,7 +2081,7 @@
         '\d\+ CMDMOD_REV\_s*' ..
         '\d\+ JUMP_IF_FALSE -> \d\+\_s*' ..
         'endif\_s*' ..
-        '\d\+ RETURN 0',
+        '\d\+ RETURN void',
         res)
 enddef
 
@@ -2104,7 +2104,7 @@
         'endfor\_s*' ..
         '\d JUMP -> 5\_s*' ..
         '8 DROP\_s*' ..
-        '\d RETURN 0\_s*',
+        '\d RETURN void\_s*',
         res)
 enddef
 
@@ -2125,7 +2125,7 @@
 
         'endwhile\_s*' ..
         '\d JUMP -> 0\_s*' ..
-        '6 RETURN 0\_s*',
+        '6 RETURN void\_s*',
          res)
 enddef
 
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 6b51bc7..d7fb1df 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -2967,6 +2967,20 @@
       assert_equal([1, 2, 3], sorted)
   END
   CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+    def RetVoid()
+    enddef
+    RetVoid()->byte2line()
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1031:')
+
+  lines =<< trim END
+    def RetVoid()
+    enddef
+    RetVoid()->byteidx(3)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1031:')
 enddef
 
 
diff --git a/src/typval.c b/src/typval.c
index a17dbef..b19140d 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -238,9 +238,11 @@
 	case VAR_BLOB:
 	    emsg(_("E974: Using a Blob as a Number"));
 	    break;
+	case VAR_VOID:
+	    emsg(_(e_cannot_use_void_value));
+	    break;
 	case VAR_UNKNOWN:
 	case VAR_ANY:
-	case VAR_VOID:
 	case VAR_INSTR:
 	    internal_error_no_abort("tv_get_number(UNKNOWN)");
 	    break;
@@ -294,7 +296,7 @@
     return tv_get_bool_or_number_chk(varp, denote, TRUE);
 }
 
-#ifdef FEAT_FLOAT
+#if defined(FEAT_FLOAT) || defined(PROTO)
     float_T
 tv_get_float(typval_T *varp)
 {
@@ -336,9 +338,11 @@
 	case VAR_BLOB:
 	    emsg(_("E975: Using a Blob as a Float"));
 	    break;
+	case VAR_VOID:
+	    emsg(_(e_cannot_use_void_value));
+	    break;
 	case VAR_UNKNOWN:
 	case VAR_ANY:
-	case VAR_VOID:
 	case VAR_INSTR:
 	    internal_error_no_abort("tv_get_float(UNKNOWN)");
 	    break;
@@ -501,9 +505,11 @@
 	    return channel_to_string_buf(varp, buf);
 #endif
 	    break;
+	case VAR_VOID:
+	    emsg(_(e_cannot_use_void_value));
+	    break;
 	case VAR_UNKNOWN:
 	case VAR_ANY:
-	case VAR_VOID:
 	case VAR_INSTR:
 	    semsg(_(e_using_invalid_value_as_string_str),
 						  vartype_name(varp->v_type));
@@ -585,6 +591,7 @@
 	case VAR_NUMBER:
 	case VAR_BOOL:
 	case VAR_SPECIAL:
+	case VAR_VOID:
 	    to->vval.v_number = from->vval.v_number;
 	    break;
 	case VAR_FLOAT:
@@ -659,7 +666,6 @@
 	    break;
 	case VAR_UNKNOWN:
 	case VAR_ANY:
-	case VAR_VOID:
 	    internal_error_no_abort("copy_tv(UNKNOWN)");
 	    break;
     }
diff --git a/src/version.c b/src/version.c
index e8b0ddc..21f5b53 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3005,
+/**/
     3004,
 /**/
     3003,
diff --git a/src/vim9.h b/src/vim9.h
index 04972dc..b8c7133 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -91,7 +91,7 @@
     ISN_PCALL,	    // call partial, use isn_arg.pfunc
     ISN_PCALL_END,  // cleanup after ISN_PCALL with cpf_top set
     ISN_RETURN,	    // return, result is on top of stack
-    ISN_RETURN_ZERO, // Push zero, then return
+    ISN_RETURN_VOID, // Push void, then return
     ISN_FUNCREF,    // push a function ref to dfunc isn_arg.funcref
     ISN_NEWFUNC,    // create a global function from a lambda function
     ISN_DEF,	    // list functions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8389399..663a52d 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -9679,8 +9679,8 @@
 	    goto erret;
 	}
 
-	// Return zero if there is no return at the end.
-	generate_instr(&cctx, ISN_RETURN_ZERO);
+	// Return void if there is no return at the end.
+	generate_instr(&cctx, ISN_RETURN_VOID);
     }
 
     // When compiled with ":silent!" and there was an error don't consider the
@@ -10047,7 +10047,7 @@
 	case ISN_REDIREND:
 	case ISN_REDIRSTART:
 	case ISN_RETURN:
-	case ISN_RETURN_ZERO:
+	case ISN_RETURN_VOID:
 	case ISN_SHUFFLE:
 	case ISN_SLICE:
 	case ISN_STORE:
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 96bd245..e464732 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2815,17 +2815,18 @@
 		}
 		break;
 
-	    // return from a :def function call
-	    case ISN_RETURN_ZERO:
+	    // return from a :def function call without a value
+	    case ISN_RETURN_VOID:
 		if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
 		    goto theend;
 		tv = STACK_TV_BOT(0);
 		++ectx->ec_stack.ga_len;
-		tv->v_type = VAR_NUMBER;
+		tv->v_type = VAR_VOID;
 		tv->vval.v_number = 0;
 		tv->v_lock = 0;
 		// FALLTHROUGH
 
+	    // return from a :def function call with what is on the stack
 	    case ISN_RETURN:
 		{
 		    garray_T	*trystack = &ectx->ec_trystack;
@@ -5076,8 +5077,8 @@
 	    case ISN_RETURN:
 		smsg("%s%4d RETURN", pfx, current);
 		break;
-	    case ISN_RETURN_ZERO:
-		smsg("%s%4d RETURN 0", pfx, current);
+	    case ISN_RETURN_VOID:
+		smsg("%s%4d RETURN void", pfx, current);
 		break;
 	    case ISN_FUNCREF:
 		{