Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 19926:d286bfc44149 v8.2.0519
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 Apr 2020 22:15:36 +0200 |
parents | 1f42c49c3d29 |
children | 2c4d9ca33769 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -380,6 +380,10 @@ def FuncOneArgRetNumber(arg: number): nu return arg enddef +def FuncOneArgRetAny(arg: any): any + return arg +enddef + def Test_func_type() let Ref1: func() funcResult = 0 @@ -417,5 +421,20 @@ def Test_func_type_fails() CheckDefFailure(['let Ref1: func()', 'Ref1 = FuncOneArgRetNumber'], 'E1013: type mismatch, expected func() but got func(number): number') enddef +def Test_func_return_type() + let nr: number + nr = FuncNoArgRetNumber() + assert_equal(1234, nr) + + nr = FuncOneArgRetAny(122) + assert_equal(122, nr) + + let str: string + str = FuncOneArgRetAny('yes') + assert_equal('yes', str) + + CheckDefFailure(['let str: string', 'str = FuncNoArgRetNumber()'], 'E1013: type mismatch, expected string but got number') +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker