Mercurial > vim
annotate src/proto/vim9type.pro @ 33949:84b93d95a952 v9.0.2169
patch 9.0.2169: Vim9: builtin funcs may accept a non-value
Commit: https://github.com/vim/vim/commit/d8bf87c9fbd92fd6b837446e886d47e557adadbc
Author: Ernie Rael <errael@raelity.com>
Date: Sat Dec 16 14:03:33 2023 +0100
patch 9.0.2169: Vim9: builtin funcs may accept a non-value
Problem: Vim9: builtin funcs may accept a non-value
Solution: Restrict builtin functions that accept `type`
This PR finishes off detection and prevention of using a type as a
value. It takes care of builtin functions. However there are some
builtin functions, that need to be able to handle types as well as
non-args: instanceof(), type(), typename(), string().
A "bit", FE_X, is added to funcentry_T; when set, the builtin function
can handle a type (class or type-alias) in addition to a value.
Noteworthy change: Discovered that in compile_call() the builtin add()
is compiled inline instead of calling the builtin. Had to add a check
there.
closes: #13688
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Dec 2023 14:15:03 +0100 |
parents | a49ae967e9ed |
children |
rev | line source |
---|---|
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vim9type.c */ |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
2 type_T *get_type_ptr(garray_T *type_gap); |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
27567
diff
changeset
|
3 type_T *copy_type(type_T *type, garray_T *type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 void clear_type_list(garray_T *gap); |
33915
a49ae967e9ed
patch 9.0.2158: [security]: use-after-free in check_argument_type
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
5 void clear_func_type_list(garray_T *gap, type_T **func_type); |
22284
6b385c2b9ff5
patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
6 type_T *alloc_type(type_T *type); |
6b385c2b9ff5
patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
7 void free_type(type_T *type); |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
8 void set_tv_type(typval_T *tv, type_T *type); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 type_T *get_list_type(type_T *member_type, garray_T *type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 type_T *get_dict_type(type_T *member_type, garray_T *type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 type_T *alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 type_T *get_func_type(type_T *ret_type, int argcount, garray_T *type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 int func_type_add_arg_types(type_T *functype, int argcount, garray_T *type_gap); |
30737
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
14 int type_any_or_unknown(type_T *type); |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22184
diff
changeset
|
15 int need_convert_to_bool(type_T *type, typval_T *tv); |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
16 type_T *typval2type(typval_T *tv, int copyID, garray_T *type_gap, int flags); |
31443
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31396
diff
changeset
|
17 int valid_declaration_type(type_T *type); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 type_T *typval2type_vimvar(typval_T *tv, garray_T *type_gap); |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
24438
diff
changeset
|
19 int check_typval_arg_type(type_T *expected, typval_T *actual_tv, char *func_name, int arg_idx); |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23640
diff
changeset
|
20 int check_typval_type(type_T *expected, typval_T *actual_tv, where_T where); |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23640
diff
changeset
|
21 void arg_type_mismatch(type_T *expected, type_T *actual, int arg_idx); |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23640
diff
changeset
|
22 void type_mismatch_where(type_T *expected, type_T *actual, where_T where); |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23640
diff
changeset
|
23 int check_type(type_T *expected, type_T *actual, int give_msg, where_T where); |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
24 int check_type_maybe(type_T *expected, type_T *actual, int give_msg, where_T where); |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
26935
diff
changeset
|
25 int check_argument_types(type_T *type, typval_T *argvars, int argcount, typval_T *base_tv, char_u *name); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 char_u *skip_type(char_u *start, int optional); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
27 type_T *parse_type(char_u **arg, garray_T *type_gap, int give_error); |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
28 int equal_type(type_T *type1, type_T *type2, int flags); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap); |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
30 int push_type_stack(cctx_T *cctx, type_T *type); |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
31 int push_type_stack2(cctx_T *cctx, type_T *type, type_T *decl_type); |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
32 void set_type_on_stack(cctx_T *cctx, type_T *type, int offset); |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
33 type_T *get_type_on_stack(cctx_T *cctx, int offset); |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
34 type_T *get_decl_type_on_stack(cctx_T *cctx, int offset); |
27567
5bf2fca4f967
patch 8.2.4310: Vim9: constant list and dict get a declaration type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
35 type_T *get_member_type_from_stack(int count, int skip, cctx_T *cctx); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 char *vartype_name(vartype_T type); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 char *type_name(type_T *type, char **tofree); |
23594
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
38 void f_typename(typval_T *argvars, typval_T *rettv); |
33913
a259471e74fe
patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents:
31443
diff
changeset
|
39 int check_typval_is_value(typval_T *tv); |
a259471e74fe
patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents:
31443
diff
changeset
|
40 int check_type_is_value(type_T *type); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 /* vim: set ft=c : */ |