diff options
author | Ernie Rael <errael@raelity.com> | 2023-10-21 11:45:38 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-21 11:45:38 +0200 |
commit | 3ec6c1fe3bb1b366b710d3e7226f7eed3be1801a (patch) | |
tree | db19fb62d95aae1ff003d0a5750cdf342c3d6340 /runtime/doc/vim9.txt | |
parent | d3e277f279ed628809eb6857ea3ebcfca566ca2a (diff) |
patch 9.0.2057: Vim9: no strict type checks for funcrefs varargsv9.0.2057
Problem: Vim9: no strict type checks for funcrefs varargs
Solution: Perform strict type checking when declaring funcrefs
with vararg declaration, add tests
closes: #13397
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
Diffstat (limited to 'runtime/doc/vim9.txt')
-rw-r--r-- | runtime/doc/vim9.txt | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt index 6cabb870d8..58d9ed6142 100644 --- a/runtime/doc/vim9.txt +++ b/runtime/doc/vim9.txt @@ -1468,7 +1468,7 @@ return value) results in error *E1031* *E1186* . There is no array type, use list<{type}> instead. For a list constant an efficient implementation is used that avoids allocating a lot of small pieces of memory. - *E1005* *E1007* + *vim9-func-declaration* *E1005* *E1007* A partial and function can be declared in more or less specific ways: func any kind of function reference, no type checking for arguments or return value @@ -1669,6 +1669,26 @@ Same for |extend()|, use |extendnew()| instead, and for |flatten()|, use |flattennew()| instead. Since |flatten()| is intended to always change the type, it can not be used in Vim9 script. +Assigning to a funcref with specified arguments (see |vim9-func-declaration|) +does strict type checking of the arguments. For variable number of arguments +the type must match: > + var FuncRef: func(string, number, bool): number + FuncRef = (v1: string, v2: number, v3: bool) => 777 # OK + FuncRef = (v1: string, v2: number, v3: number) => 777 # Error! + # variable number of arguments must have same type + var FuncVA: func(...list<string>): number + FuncVA = (...v: list<number>): number => v # Error! + FuncVA = (...v: list<any>): number => v # OK, `any` runtime check + FuncVA = (v1: string, v: string2): number => 333 # Error! + FuncVA = (v: list<string>): number => 3 # Error! + +If the destinataion funcref has no specified arguments, then there is no +argument type checking: > + var FuncUnknownArgs: func: number + FuncUnknownArgs = (v): number => v # OK + FuncUnknownArgs = (v1: string, v2: string): number => 3 # OK +< FuncUnknownArgs = (...v1: list<string>): number => 333 # OK + *E1211* *E1217* *E1218* *E1219* *E1220* *E1221* *E1222* *E1223* *E1224* *E1225* *E1226* *E1227* *E1228* *E1238* *E1250* *E1251* *E1252* *E1256* |