• R/O
  • SSH

vim: 提交

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


Commit MetaInfo

修訂d286bfc441496bfce303766c8f36b871ae6d4983 (tree)
時間2020-04-06 05:15:36
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0519: Vim9: return type not properly checked

Commit: https://github.com/vim/vim/commit/8922860afb2cf9e89417c0c1417f1fb4458d3b44
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 5 22:14:54 2020 +0200

patch 8.2.0519: Vim9: return type not properly checked
Problem: Vim9: return type not properly checked.
Solution: Check type properly, also at runtime.

Change Summary

差異

diff -r 8c9845101214 -r d286bfc44149 src/testdir/test_vim9_func.vim
--- a/src/testdir/test_vim9_func.vim Sun Apr 05 21:45:27 2020 +0200
+++ b/src/testdir/test_vim9_func.vim Sun Apr 05 22:15:36 2020 +0200
@@ -380,6 +380,10 @@
380380 return arg
381381 enddef
382382
383+def FuncOneArgRetAny(arg: any): any
384+ return arg
385+enddef
386+
383387 def Test_func_type()
384388 let Ref1: func()
385389 funcResult = 0
@@ -417,5 +421,20 @@
417421 CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number')
418422 enddef
419423
424+def Test_func_return_type()
425+ let nr: number
426+ nr = FuncNoArgRetNumber()
427+ assert_equal(1234, nr)
428+
429+ nr = FuncOneArgRetAny(122)
430+ assert_equal(122, nr)
431+
432+ let str: string
433+ str = FuncOneArgRetAny('yes')
434+ assert_equal('yes', str)
435+
436+ CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1013: type mismatch, expected string but got number')
437+enddef
438+
420439
421440 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff -r 8c9845101214 -r d286bfc44149 src/version.c
--- a/src/version.c Sun Apr 05 21:45:27 2020 +0200
+++ b/src/version.c Sun Apr 05 22:15:36 2020 +0200
@@ -739,6 +739,8 @@
739739 static int included_patches[] =
740740 { /* Add new patch number below this line */
741741 /**/
742+ 519,
743+/**/
742744 518,
743745 /**/
744746 517,
diff -r 8c9845101214 -r d286bfc44149 src/vim9compile.c
--- a/src/vim9compile.c Sun Apr 05 21:45:27 2020 +0200
+++ b/src/vim9compile.c Sun Apr 05 22:15:36 2020 +0200
@@ -2432,7 +2432,7 @@
24322432 if (ret == FAIL && give_msg)
24332433 type_mismatch(expected, actual);
24342434 }
2435- return OK;
2435+ return ret;
24362436 }
24372437
24382438 /*
@@ -2444,7 +2444,7 @@
24442444 static int
24452445 need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx)
24462446 {
2447- if (check_type(expected, actual, FALSE))
2447+ if (check_type(expected, actual, FALSE) == OK)
24482448 return OK;
24492449 if (actual->tt_type != VAR_ANY && actual->tt_type != VAR_UNKNOWN)
24502450 {
@@ -4069,7 +4069,7 @@
40694069 lvar->lv_type = stacktype;
40704070 }
40714071 }
4072- else if (check_type(lvar->lv_type, stacktype, TRUE) == FAIL)
4072+ else if (need_type(stacktype, lvar->lv_type, -1, cctx) == FAIL)
40734073 goto theend;
40744074 }
40754075 else if (*p != '=' && check_type(type, stacktype, TRUE) == FAIL)
Show on old repository browser