return arg
enddef
+def FuncOneArgRetAny(arg: any): any
+ return arg
+enddef
+
def Test_func_type()
let Ref1: func()
funcResult = 0
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
if (ret == FAIL && give_msg)
type_mismatch(expected, actual);
}
- return OK;
+ return ret;
}
/*
static int
need_type(type_T *actual, type_T *expected, int offset, cctx_T *cctx)
{
- if (check_type(expected, actual, FALSE))
+ if (check_type(expected, actual, FALSE) == OK)
return OK;
if (actual->tt_type != VAR_ANY && actual->tt_type != VAR_UNKNOWN)
{
lvar->lv_type = stacktype;
}
}
- else if (check_type(lvar->lv_type, stacktype, TRUE) == FAIL)
+ else if (need_type(stacktype, lvar->lv_type, -1, cctx) == FAIL)
goto theend;
}
else if (*p != '=' && check_type(type, stacktype, TRUE) == FAIL)