• R/O
  • SSH

vim: コミット

Mirror of the Vim source from https://github.com/vim/vim


コミットメタ情報

リビジョン47dbeda35910f460cbbe120c33d3f5c7fd027e93 (tree)
日時2022-01-19 04:00:03
作者Bram Moolenaar <Bram@vim....>
コミッターBram Moolenaar

ログメッセージ

patch 8.2.4138: Vim9: no error for return with argument when invalid

Commit: https://github.com/vim/vim/commit/ef7aadbe36ad43a1b909f5f6c7e9b170ad62ef91
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 18 18:46:07 2022 +0000

patch 8.2.4138: Vim9: no error for return with argument when invalid
Problem: Vim9: no error for return with argument when the function does not
return anything.
Solution: Give an error for the invalid argument. (issue #9497)

変更サマリ

差分

diff -r daeffa5e4c8c -r 47dbeda35910 src/testdir/test_vim9_func.vim
--- a/src/testdir/test_vim9_func.vim Tue Jan 18 18:45:03 2022 +0100
+++ b/src/testdir/test_vim9_func.vim Tue Jan 18 20:00:03 2022 +0100
@@ -341,6 +341,20 @@
341341 ReturnString()->assert_equal('string')
342342 ReturnNumber()->assert_equal(123)
343343 assert_fails('ReturnGlobal()', 'E1012: Type mismatch; expected number but got string', '', 1, 'ReturnGlobal')
344+
345+ var lines =<< trim END
346+ vim9script
347+
348+ def Msg()
349+ echomsg 'in Msg()...'
350+ enddef
351+
352+ def Func()
353+ return Msg()
354+ enddef
355+ defcompile
356+ END
357+ CheckScriptFailure(lines, 'E1096:')
344358 enddef
345359
346360 def Test_check_argument_type()
diff -r daeffa5e4c8c -r 47dbeda35910 src/version.c
--- a/src/version.c Tue Jan 18 18:45:03 2022 +0100
+++ b/src/version.c Tue Jan 18 20:00:03 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4138,
755+/**/
754756 4137,
755757 /**/
756758 4136,
diff -r daeffa5e4c8c -r 47dbeda35910 src/vim9cmds.c
--- a/src/vim9cmds.c Tue Jan 18 18:45:03 2022 +0100
+++ b/src/vim9cmds.c Tue Jan 18 20:00:03 2022 +0100
@@ -2196,6 +2196,11 @@
21962196
21972197 if (*p != NUL && *p != '|' && *p != '\n')
21982198 {
2199+ if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID)
2200+ {
2201+ emsg(_(e_returning_value_in_function_without_return_type));
2202+ return NULL;
2203+ }
21992204 if (legacy)
22002205 {
22012206 int save_flags = cmdmod.cmod_flags;
@@ -2231,13 +2236,6 @@
22312236 }
22322237 else
22332238 {
2234- if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
2235- && stack_type->tt_type != VAR_VOID
2236- && stack_type->tt_type != VAR_UNKNOWN)
2237- {
2238- emsg(_(e_returning_value_in_function_without_return_type));
2239- return NULL;
2240- }
22412239 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
22422240 0, cctx, FALSE, FALSE) == FAIL)
22432241 return NULL;
旧リポジトリブラウザで表示