comparison src/testdir/test_vim9_func.vim @ 24156:a358fa462560 v8.2.2619

patch 8.2.2619: Vim9: no test for return type of lambda Commit: https://github.com/vim/vim/commit/5f91e74bf968c9033474086b2d9cb457281c8aa6 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 17 21:29:29 2021 +0100 patch 8.2.2619: Vim9: no test for return type of lambda Problem: Vim9: no test for return type of lambda. Solution: Add a test.
author Bram Moolenaar <Bram@vim.org>
date Wed, 17 Mar 2021 21:30:02 +0100
parents c308076e225e
children 7a21b2581dce
comparison
equal deleted inserted replaced
24155:17e994bcd7bb 24156:a358fa462560
750 enddef 750 enddef
751 END 751 END
752 CheckDefFailure(lines, 'E1167:') 752 CheckDefFailure(lines, 'E1167:')
753 enddef 753 enddef
754 754
755 def FilterWithCond(x: string, Cond: func(string): bool): bool
756 return Cond(x)
757 enddef
758
755 def Test_lambda_return_type() 759 def Test_lambda_return_type()
756 var lines =<< trim END 760 var lines =<< trim END
757 var Ref = (): => 123 761 var Ref = (): => 123
758 END 762 END
759 CheckDefAndScriptFailure(lines, 'E1157:', 1) 763 CheckDefAndScriptFailure(lines, 'E1157:', 1)
764
765 # this works
766 for x in ['foo', 'boo']
767 echo FilterWithCond(x, (v) => v =~ '^b')
768 endfor
769
770 # this fails
771 lines =<< trim END
772 echo FilterWithCond('foo', (v) => v .. '^b')
773 END
774 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected func(string): bool but got func(any): string', 1)
760 enddef 775 enddef
761 776
762 def Test_lambda_uses_assigned_var() 777 def Test_lambda_uses_assigned_var()
763 CheckDefSuccess([ 778 CheckDefSuccess([
764 'var x: any = "aaa"' 779 'var x: any = "aaa"'