To: vim_dev@googlegroups.com Subject: Patch 8.2.1131 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1131 Problem: Vim9: error message for returning a value in a function that does not return anything is not clear. Solution: Add a specific message. Files: src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1130/src/vim9compile.c 2020-07-05 15:32:09.315656860 +0200 --- src/vim9compile.c 2020-07-05 15:41:48.321752016 +0200 *************** *** 4568,4576 **** stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; if (set_return_type) cctx->ctx_ufunc->uf_ret_type = stack_type; ! else if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, cctx) == FAIL) return NULL; } else { --- 4568,4586 ---- stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; if (set_return_type) cctx->ctx_ufunc->uf_ret_type = stack_type; ! else ! { ! if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID ! && stack_type->tt_type != VAR_VOID ! && stack_type->tt_type != VAR_UNKNOWN) ! { ! emsg(_("E1096: Returning a value in a function without a return type")); ! return NULL; ! } ! if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, cctx) == FAIL) return NULL; + } } else { *** ../vim-8.2.1130/src/testdir/test_vim9_func.vim 2020-07-01 17:28:30.343443234 +0200 --- src/testdir/test_vim9_func.vim 2020-07-05 15:45:05.349058633 +0200 *************** *** 286,299 **** def Test_error_in_nested_function() " Error in called function requires unwinding the call stack. ! assert_fails('call FuncWithForwardCall()', 'E1013') enddef def Test_return_type_wrong() CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef', 'defcompile'], 'expected number but got string') CheckScriptFailure(['def Func(): string', 'return 1', 'enddef', 'defcompile'], 'expected string but got number') ! CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef', 'defcompile'], 'expected void but got string') ! CheckScriptFailure(['def Func()', 'return "a"', 'enddef', 'defcompile'], 'expected void but got string') CheckScriptFailure(['def Func(): number', 'return', 'enddef', 'defcompile'], 'E1003:') --- 286,299 ---- def Test_error_in_nested_function() " Error in called function requires unwinding the call stack. ! assert_fails('call FuncWithForwardCall()', 'E1096') enddef def Test_return_type_wrong() CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef', 'defcompile'], 'expected number but got string') CheckScriptFailure(['def Func(): string', 'return 1', 'enddef', 'defcompile'], 'expected string but got number') ! CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') ! CheckScriptFailure(['def Func()', 'return "a"', 'enddef', 'defcompile'], 'E1096: Returning a value in a function without a return type') CheckScriptFailure(['def Func(): number', 'return', 'enddef', 'defcompile'], 'E1003:') *** ../vim-8.2.1130/src/version.c 2020-07-05 15:32:09.315656860 +0200 --- src/version.c 2020-07-05 15:42:57.325510834 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1131, /**/ -- BEDEVERE: Why do you think she is a witch? SECOND VILLAGER: She turned me into a newt. BEDEVERE: A newt? SECOND VILLAGER: (After looking at himself for some time) I got better. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///