def Test_error_in_nested_function()
" Error in called function requires unwinding the call stack.
- assert_fails('call FuncWithForwardCall()', 'E1013')
+ 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'], 'expected void but got string')
- CheckScriptFailure(['def Func()', 'return "a"', 'enddef', 'defcompile'], 'expected void but got string')
+ 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:')
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)
+ 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
{