comparison src/testdir/test_vim9_func.vim @ 21693:4e4fd845553d v8.2.1396

patch 8.2.1396: Vim9: no error for unexpectedly returning a value Commit: https://github.com/vim/vim/commit/5a849da57c5fb54ffcffd436a9e00ef40fdf094c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 8 16:47:30 2020 +0200 patch 8.2.1396: Vim9: no error for unexpectedly returning a value Problem: Vim9: no error for unexpectedly returning a value. Solution: Only set the return type for lambda's. Make using function type in a function reference work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 08 Aug 2020 17:00:04 +0200
parents 10866fd07595
children 7e1316c6d0eb
comparison
equal deleted inserted replaced
21692:c008e8068ad8 21693:4e4fd845553d
501 # Error in called function requires unwinding the call stack. 501 # Error in called function requires unwinding the call stack.
502 assert_fails('call FuncWithForwardCall()', 'E1096') 502 assert_fails('call FuncWithForwardCall()', 'E1096')
503 enddef 503 enddef
504 504
505 def Test_return_type_wrong() 505 def Test_return_type_wrong()
506 CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef', 'defcompile'], 'expected number but got string') 506 CheckScriptFailure([
507 CheckScriptFailure(['def Func(): string', 'return 1', 'enddef', 'defcompile'], 'expected string but got number') 507 'def Func(): number',
508 CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') 508 'return "a"',
509 CheckScriptFailure(['def Func()', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') 509 'enddef',
510 510 'defcompile'], 'expected number but got string')
511 CheckScriptFailure(['def Func(): number', 'return', 'enddef', 'defcompile'], 'E1003:') 511 CheckScriptFailure([
512 'def Func(): string',
513 'return 1',
514 'enddef',
515 'defcompile'], 'expected string but got number')
516 CheckScriptFailure([
517 'def Func(): void',
518 'return "a"',
519 'enddef',
520 'defcompile'],
521 'E1096: Returning a value in a function without a return type')
522 CheckScriptFailure([
523 'def Func()',
524 'return "a"',
525 'enddef',
526 'defcompile'],
527 'E1096: Returning a value in a function without a return type')
528
529 CheckScriptFailure([
530 'def Func(): number',
531 'return',
532 'enddef',
533 'defcompile'], 'E1003:')
512 534
513 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:') 535 CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
514 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:') 536 CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
515 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:') 537 CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
538
539 CheckScriptFailure([
540 'vim9script',
541 'def FuncB()',
542 ' return 123',
543 'enddef',
544 'def FuncA()',
545 ' FuncB()',
546 'enddef',
547 'defcompile'], 'E1096:')
516 enddef 548 enddef
517 549
518 def Test_arg_type_wrong() 550 def Test_arg_type_wrong()
519 CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>') 551 CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
520 CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...') 552 CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')