Mercurial > vim
annotate src/vim9type.c @ 28514:0f69ddbdde1f
Added tag v8.2.4781 for changeset 6a1e5b188374b4d58fcccbbdccd2727d0e93c3a0
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 18 Apr 2022 15:45:03 +0200 |
parents | c446812efd60 |
children | ba083decce5d |
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 /* vi:set ts=8 sts=4 sw=4 noet: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * vim9type.c: handling of types |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #define USING_FLOAT_STUFF |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 #include "vim.h" |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 #if defined(FEAT_EVAL) || defined(PROTO) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 #ifdef VMS |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 # include <float.h> |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 #endif |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 * Allocate memory for a type_T and add the pointer to type_gap, so that it can |
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
|
25 * be easily freed later. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25465
diff
changeset
|
27 static type_T * |
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
|
28 get_type_ptr(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
|
29 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 if (ga_grow(type_gap, 1) == FAIL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 return NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 type = ALLOC_CLEAR_ONE(type_T); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 if (type != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 ((type_T **)type_gap->ga_data)[type_gap->ga_len] = type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 ++type_gap->ga_len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 void |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 clear_type_list(garray_T *gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 while (gap->ga_len > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 vim_free(((type_T **)gap->ga_data)[--gap->ga_len]); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 ga_clear(gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 |
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
|
51 /* |
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
|
52 * Take a type that is using entries in a growarray and turn it into a 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
|
53 * with allocated entries. |
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
|
54 */ |
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
|
55 type_T * |
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
|
56 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
|
57 { |
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
|
58 type_T *ret; |
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
|
59 |
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
|
60 if (type == NULL) |
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
|
61 return NULL; |
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
|
62 |
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
|
63 // A fixed type never contains allocated types, return as-is. |
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
|
64 if (type->tt_flags & TTFLAG_STATIC) |
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
|
65 return 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
|
66 |
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
|
67 ret = ALLOC_ONE(type_T); |
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
|
68 *ret = *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
|
69 |
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
|
70 if (ret->tt_member != NULL) |
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
|
71 ret->tt_member = alloc_type(ret->tt_member); |
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
|
72 if (type->tt_args != NULL) |
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
|
73 { |
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
|
74 int i; |
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
|
75 |
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
|
76 ret->tt_args = ALLOC_MULT(type_T *, type->tt_argcount); |
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
|
77 if (ret->tt_args != NULL) |
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
|
78 for (i = 0; i < type->tt_argcount; ++i) |
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
|
79 ret->tt_args[i] = alloc_type(type->tt_args[i]); |
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
|
80 } |
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
|
81 |
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
|
82 return ret; |
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
|
83 } |
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
|
84 |
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
|
85 /* |
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
|
86 * Free a type that was created with alloc_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
|
87 */ |
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
|
88 void |
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
|
89 free_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
|
90 { |
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
|
91 int i; |
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
|
92 |
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
|
93 if (type == NULL || (type->tt_flags & TTFLAG_STATIC)) |
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
|
94 return; |
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
|
95 if (type->tt_args != NULL) |
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
|
96 { |
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
|
97 for (i = 0; i < type->tt_argcount; ++i) |
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
|
98 free_type(type->tt_args[i]); |
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
|
99 vim_free(type->tt_args); |
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
|
100 } |
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
|
101 free_type(type->tt_member); |
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
|
102 vim_free(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
|
103 } |
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
|
104 |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
105 /* |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
106 * Return TRUE if "type" is to be recursed into for setting the type. |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
107 */ |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
108 static int |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
109 set_tv_type_recurse(type_T *type) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
110 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
111 return type->tt_member != NULL |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
112 && (type->tt_member->tt_type == VAR_DICT |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
113 || type->tt_member->tt_type == VAR_LIST) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
114 && type->tt_member->tt_member != NULL |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
115 && type->tt_member->tt_member != &t_any |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
116 && type->tt_member->tt_member != &t_unknown; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
117 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
118 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
119 /* |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
120 * Set the type of "tv" to "type" if it is a list or dict. |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
121 */ |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
122 void |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
123 set_tv_type(typval_T *tv, type_T *type) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
124 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
125 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
126 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
127 dict_T *d = tv->vval.v_dict; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
128 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
129 if (d->dv_type != type) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
130 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
131 free_type(d->dv_type); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
132 d->dv_type = alloc_type(type); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
133 if (set_tv_type_recurse(type)) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
134 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
135 int todo = (int)d->dv_hashtab.ht_used; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
136 hashitem_T *hi; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
137 dictitem_T *di; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
138 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
139 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
140 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
141 if (!HASHITEM_EMPTY(hi)) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
142 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
143 --todo; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
144 di = HI2DI(hi); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
145 set_tv_type(&di->di_tv, type->tt_member); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
146 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
147 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
148 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
149 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
150 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
151 else if (tv->v_type == VAR_LIST && tv->vval.v_list != NULL) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
152 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
153 list_T *l = tv->vval.v_list; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
154 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
155 if (l->lv_type != type) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
156 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
157 free_type(l->lv_type); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
158 l->lv_type = alloc_type(type); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
159 if (l->lv_first != &range_list_item && set_tv_type_recurse(type)) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
160 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
161 listitem_T *li; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
162 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
163 FOR_ALL_LIST_ITEMS(l, li) |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
164 set_tv_type(&li->li_tv, type->tt_member); |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
165 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
166 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
167 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
168 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
169 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 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
|
172 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 // recognize commonly used types |
22804
af26fadf333d
patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents:
22494
diff
changeset
|
176 if (member_type == NULL || member_type->tt_type == VAR_ANY) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 return &t_list_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 if (member_type->tt_type == VAR_VOID |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 || member_type->tt_type == VAR_UNKNOWN) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 return &t_list_empty; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 if (member_type->tt_type == VAR_BOOL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 return &t_list_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 if (member_type->tt_type == VAR_NUMBER) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 return &t_list_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 if (member_type->tt_type == VAR_STRING) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 return &t_list_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 // Not a common type, create a new entry. |
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
|
189 type = get_type_ptr(type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 type->tt_type = VAR_LIST; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 type->tt_member = member_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 type->tt_argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 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
|
201 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 // recognize commonly used types |
22804
af26fadf333d
patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents:
22494
diff
changeset
|
205 if (member_type == NULL || member_type->tt_type == VAR_ANY) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 return &t_dict_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 if (member_type->tt_type == VAR_VOID |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 || member_type->tt_type == VAR_UNKNOWN) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 return &t_dict_empty; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 if (member_type->tt_type == VAR_BOOL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 return &t_dict_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 if (member_type->tt_type == VAR_NUMBER) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 return &t_dict_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 if (member_type->tt_type == VAR_STRING) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 return &t_dict_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 // Not a common type, create a new entry. |
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
|
218 type = get_type_ptr(type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 type->tt_type = VAR_DICT; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 type->tt_member = member_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 type->tt_argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 * Allocate a new type for a function. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 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
|
233 { |
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
|
234 type_T *type = get_type_ptr(type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 type->tt_type = VAR_FUNC; |
24996
0136c6ee1961
patch 8.2.3035: Vim9: crash when calling :def function with partial
Bram Moolenaar <Bram@vim.org>
parents:
24895
diff
changeset
|
239 type->tt_member = ret_type == NULL ? &t_unknown : ret_type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 type->tt_argcount = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 * Get a function type, based on the return type "ret_type". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 * If "argcount" is -1 or 0 a predefined type can be used. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 * If "argcount" > 0 always create a new type, so that arguments can be added. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 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
|
252 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 // recognize commonly used types |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 if (argcount <= 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 { |
24996
0136c6ee1961
patch 8.2.3035: Vim9: crash when calling :def function with partial
Bram Moolenaar <Bram@vim.org>
parents:
24895
diff
changeset
|
256 if (ret_type == &t_unknown || ret_type == NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 // (argcount == 0) is not possible |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 return &t_func_unknown; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 if (ret_type == &t_void) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 if (argcount == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 return &t_func_0_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 return &t_func_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 if (ret_type == &t_any) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 if (argcount == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 return &t_func_0_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 return &t_func_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 if (ret_type == &t_number) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 if (argcount == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 return &t_func_0_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 return &t_func_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 if (ret_type == &t_string) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 if (argcount == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 return &t_func_0_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 return &t_func_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 return alloc_func_type(ret_type, argcount, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 * For a function type, reserve space for "argcount" argument types (including |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 * vararg). |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 int |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 func_type_add_arg_types( |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 type_T *functype, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 int argcount, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 garray_T *type_gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 // To make it easy to free the space needed for the argument types, add the |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 // pointer to type_gap. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 if (ga_grow(type_gap, 1) == FAIL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
308 functype->tt_args = ALLOC_CLEAR_MULT(type_T *, argcount); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 if (functype->tt_args == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 ((type_T **)type_gap->ga_data)[type_gap->ga_len] = |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 (void *)functype->tt_args; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 ++type_gap->ga_len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 return OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
315 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 * Get a type_T for a typval_T. |
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
|
319 * "type_gap" is used to temporarily create types in. |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
320 * When "flags" has TVTT_DO_MEMBER also get the member type, otherwise use |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
321 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
322 * When "flags" has TVTT_MORE_SPECIFIC get the more specific member type if it |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
323 * is "any". |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 */ |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
325 static type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
326 typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int flags) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 { |
22190
da851f3b6a0b
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents:
22184
diff
changeset
|
328 type_T *type; |
25788
b2c00659152a
patch 8.2.3429: leaking memory when assigning to list or dict
Bram Moolenaar <Bram@vim.org>
parents:
25692
diff
changeset
|
329 type_T *member_type = NULL; |
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
|
330 int argcount = 0; |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
331 int min_argcount = 0; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
333 if (tv->v_type == VAR_NUMBER) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 if (tv->v_type == VAR_BOOL) |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
336 return &t_bool; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 if (tv->v_type == VAR_STRING) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 return &t_string; |
25788
b2c00659152a
patch 8.2.3429: leaking memory when assigning to list or dict
Bram Moolenaar <Bram@vim.org>
parents:
25692
diff
changeset
|
339 if (tv->v_type == VAR_BLOB) |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
340 { |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
341 if (tv->vval.v_blob == NULL) |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
342 return &t_blob_null; |
25788
b2c00659152a
patch 8.2.3429: leaking memory when assigning to list or dict
Bram Moolenaar <Bram@vim.org>
parents:
25692
diff
changeset
|
343 return &t_blob; |
28231
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
344 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 if (tv->v_type == VAR_LIST) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 { |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
348 list_T *l = tv->vval.v_list; |
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
349 listitem_T *li; |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
350 |
27519
7898c7847293
patch 8.2.4287: cannot assign empty list with type to variable with list type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
351 // An empty list has type list<unknown>, unless the type was specified |
7898c7847293
patch 8.2.4287: cannot assign empty list with type to variable with list type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
352 // and is not list<any>. This matters when assigning to a variable |
7898c7847293
patch 8.2.4287: cannot assign empty list with type to variable with list type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
353 // with a specific list type. |
7898c7847293
patch 8.2.4287: cannot assign empty list with type to variable with list type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
354 if (l == NULL || (l->lv_first == NULL |
7898c7847293
patch 8.2.4287: cannot assign empty list with type to variable with list type
Bram Moolenaar <Bram@vim.org>
parents:
27517
diff
changeset
|
355 && (l->lv_type == NULL || l->lv_type->tt_member == &t_any))) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 return &t_list_empty; |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
357 if ((flags & TVTT_DO_MEMBER) == 0) |
24438
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
358 return &t_list_any; |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
359 // If the type is list<any> go through the members, it may end up a |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
360 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
361 if (l->lv_type != NULL && (l->lv_first == NULL |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
362 || (flags & TVTT_MORE_SPECIFIC) == 0 |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
363 || l->lv_type->tt_member != &t_any)) |
25571
951f3e04e238
patch 8.2.3322: Vim9: checking type of dict does not check member type
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
364 return l->lv_type; |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
365 if (l->lv_first == &range_list_item) |
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
366 return &t_list_number; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
367 if (l->lv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
368 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
369 return &t_list_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
370 l->lv_copyID = copyID; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
372 // Use the common type of all members. |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
373 member_type = typval2type(&l->lv_first->li_tv, copyID, type_gap, |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
374 TVTT_DO_MEMBER); |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
375 for (li = l->lv_first->li_next; li != NULL; li = li->li_next) |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
376 common_type(typval2type(&li->li_tv, copyID, type_gap, |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
377 TVTT_DO_MEMBER), |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
378 member_type, &member_type, type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 return get_list_type(member_type, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 if (tv->v_type == VAR_DICT) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 dict_iterator_T iter; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 typval_T *value; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
386 dict_T *d = tv->vval.v_dict; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 |
25571
951f3e04e238
patch 8.2.3322: Vim9: checking type of dict does not check member type
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
388 if (d == NULL || (d->dv_hashtab.ht_used == 0 && d->dv_type == NULL)) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 return &t_dict_empty; |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
390 if ((flags & TVTT_DO_MEMBER) == 0) |
24438
5c6ccab68d1e
patch 8.2.2759: Vim9: for loop infers type of loop variable
Bram Moolenaar <Bram@vim.org>
parents:
24160
diff
changeset
|
391 return &t_dict_any; |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
392 // If the type is dict<any> go through the members, it may end up a |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
393 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
394 if (d->dv_type != NULL && (d->dv_hashtab.ht_used == 0 |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
395 || (flags & TVTT_MORE_SPECIFIC) == 0 |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
396 || d->dv_type->tt_member != &t_any)) |
25571
951f3e04e238
patch 8.2.3322: Vim9: checking type of dict does not check member type
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
397 return d->dv_type; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
398 if (d->dv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
399 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
400 return &t_dict_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
401 d->dv_copyID = copyID; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
403 // Use the common type of all values. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 dict_iterate_start(tv, &iter); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 dict_iterate_next(&iter, &value); |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
406 member_type = typval2type(value, copyID, type_gap, TVTT_DO_MEMBER); |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
407 while (dict_iterate_next(&iter, &value) != NULL) |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
408 common_type(typval2type(value, copyID, type_gap, TVTT_DO_MEMBER), |
21803
e591b448a670
patch 8.2.1451: Vim9: list type at script level only uses first item
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
409 member_type, &member_type, type_gap); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 return get_dict_type(member_type, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 if (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 char_u *name = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 ufunc_T *ufunc = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 |
25692
17830c066d4b
patch 8.2.3382: crash when getting the type of a NULL partial
Bram Moolenaar <Bram@vim.org>
parents:
25646
diff
changeset
|
418 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 if (tv->vval.v_partial->pt_func != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 ufunc = tv->vval.v_partial->pt_func; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 name = tv->vval.v_partial->pt_name; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 name = tv->vval.v_string; |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
427 if (name == NULL && ufunc == NULL) |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28002
diff
changeset
|
428 return &t_func_unknown; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 if (name != NULL) |
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
|
430 { |
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
|
431 int idx = find_internal_func(name); |
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
|
432 |
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
|
433 if (idx >= 0) |
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
|
434 { |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
435 type_T *decl_type; // unused |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
436 |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
437 internal_func_get_argcount(idx, &argcount, &min_argcount); |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
438 member_type = internal_func_ret_type(idx, 0, NULL, &decl_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
|
439 } |
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
|
440 else |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
441 ufunc = find_func(name, FALSE); |
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
|
442 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 if (ufunc != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 // May need to get the argument types from default values by |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 // compiling the function. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 if (ufunc->uf_def_status == UF_TO_BE_COMPILED |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24606
diff
changeset
|
448 && compile_def_function(ufunc, TRUE, CT_NONE, NULL) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23640
diff
changeset
|
449 == FAIL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 return NULL; |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23334
diff
changeset
|
451 if (ufunc->uf_func_type == NULL) |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23334
diff
changeset
|
452 set_function_type(ufunc); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 if (ufunc->uf_func_type != NULL) |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
454 { |
27010
b049c3b63a67
patch 8.2.4034: Coverity warns for possibly using a NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
26939
diff
changeset
|
455 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
456 && tv->vval.v_partial->pt_argc > 0) |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
457 { |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
458 type = get_type_ptr(type_gap); |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
459 if (type == NULL) |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
460 return NULL; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
461 *type = *ufunc->uf_func_type; |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
462 if (type->tt_argcount >= 0) |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
463 { |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
464 type->tt_argcount -= tv->vval.v_partial->pt_argc; |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
465 type->tt_min_argcount -= tv->vval.v_partial->pt_argc; |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27567
diff
changeset
|
466 if (type->tt_argcount <= 0) |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
467 type->tt_args = NULL; |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
468 else |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
469 { |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
470 int i; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
471 |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
472 func_type_add_arg_types(type, type->tt_argcount, |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
473 type_gap); |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
474 for (i = 0; i < type->tt_argcount; ++i) |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
475 type->tt_args[i] = ufunc->uf_func_type->tt_args[ |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
476 i + tv->vval.v_partial->pt_argc]; |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
477 } |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
478 } |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
479 return type; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
480 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 return ufunc->uf_func_type; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
482 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
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
|
486 type = get_type_ptr(type_gap); |
22190
da851f3b6a0b
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents:
22184
diff
changeset
|
487 if (type == NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 return NULL; |
22190
da851f3b6a0b
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents:
22184
diff
changeset
|
489 type->tt_type = tv->v_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
|
490 type->tt_argcount = argcount; |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
491 type->tt_min_argcount = min_argcount; |
25692
17830c066d4b
patch 8.2.3382: crash when getting the type of a NULL partial
Bram Moolenaar <Bram@vim.org>
parents:
25646
diff
changeset
|
492 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL |
17830c066d4b
patch 8.2.3382: crash when getting the type of a NULL partial
Bram Moolenaar <Bram@vim.org>
parents:
25646
diff
changeset
|
493 && tv->vval.v_partial->pt_argc > 0) |
25465
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
494 { |
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
495 type->tt_argcount -= tv->vval.v_partial->pt_argc; |
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
496 type->tt_min_argcount -= tv->vval.v_partial->pt_argc; |
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
497 } |
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
|
498 type->tt_member = member_type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 |
22190
da851f3b6a0b
patch 8.2.1644: Vim9: cannot assign 1 and 0 to bool at script level
Bram Moolenaar <Bram@vim.org>
parents:
22184
diff
changeset
|
500 return type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 /* |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
504 * Return TRUE if "tv" is not a bool but should be converted to bool. |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
505 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
506 int |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
507 need_convert_to_bool(type_T *type, typval_T *tv) |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
508 { |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
509 return type != NULL && type == &t_bool && tv->v_type != VAR_BOOL |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
510 && (tv->v_type == VAR_NUMBER |
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
511 && (tv->vval.v_number == 0 || tv->vval.v_number == 1)); |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
512 } |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
513 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
514 /* |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
515 * Get a type_T for a typval_T. |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
516 * "type_list" is used to temporarily create types in. |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
517 * When "flags" has TVTT_DO_MEMBER also get the member type, otherwise use |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
518 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
519 * When "flags" has TVTT_MORE_SPECIFIC get the most specific member type. |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
520 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
521 type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
522 typval2type(typval_T *tv, int copyID, garray_T *type_gap, int flags) |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
523 { |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
524 type_T *type = typval2type_int(tv, copyID, type_gap, flags); |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
525 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
526 if (type != NULL && type != &t_bool |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
527 && (tv->v_type == VAR_NUMBER |
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
528 && (tv->vval.v_number == 0 || tv->vval.v_number == 1))) |
23334
4b4f695e9cd1
patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
529 // Number 0 and 1 and expression with "&&" or "||" can also be used for |
4b4f695e9cd1
patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
530 // bool. |
4b4f695e9cd1
patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
531 type = &t_number_bool; |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
532 return type; |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
533 } |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
534 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
535 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 * Get a type_T for a typval_T, used for v: variables. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 * "type_list" is used to temporarily create types in. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 typval2type_vimvar(typval_T *tv, garray_T *type_gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 if (tv->v_type == VAR_LIST) // e.g. for v:oldfiles |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 return &t_list_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 if (tv->v_type == VAR_DICT) // e.g. for v:completed_item |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 return &t_dict_any; |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
546 return typval2type(tv, get_copyID(), type_gap, TVTT_DO_MEMBER); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
549 int |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
550 check_typval_arg_type( |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
551 type_T *expected, |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
552 typval_T *actual_tv, |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
553 char *func_name, |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
554 int arg_idx) |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
555 { |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
556 where_T where = WHERE_INIT; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
557 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
558 where.wt_index = arg_idx; |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
559 where.wt_func_name = func_name; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
560 return check_typval_type(expected, actual_tv, where); |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
561 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 * Return FAIL if "expected" and "actual" don't match. |
22804
af26fadf333d
patch 8.2.1950: Vim9: crash when compiling function fails when getting type
Bram Moolenaar <Bram@vim.org>
parents:
22494
diff
changeset
|
565 * When "argidx" > 0 it is included in the error message. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 int |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
568 check_typval_type(type_T *expected, typval_T *actual_tv, where_T where) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 garray_T type_list; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 type_T *actual_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 int res = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
574 if (expected == NULL) |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
575 return OK; // didn't expect anything. |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
576 // |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
577 ga_init2(&type_list, sizeof(type_T *), 10); |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
578 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
579 // A null_function and null_partial are special cases, they can be used to |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
580 // clear a variable. |
25646
99fbffe75217
patch 8.2.3359: Vim9: error for type when variable is not set
Bram Moolenaar <Bram@vim.org>
parents:
25571
diff
changeset
|
581 if ((actual_tv->v_type == VAR_FUNC && actual_tv->vval.v_string == NULL) |
99fbffe75217
patch 8.2.3359: Vim9: error for type when variable is not set
Bram Moolenaar <Bram@vim.org>
parents:
25571
diff
changeset
|
582 || (actual_tv->v_type == VAR_PARTIAL |
99fbffe75217
patch 8.2.3359: Vim9: error for type when variable is not set
Bram Moolenaar <Bram@vim.org>
parents:
25571
diff
changeset
|
583 && actual_tv->vval.v_partial == NULL)) |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
584 actual_type = &t_func_unknown; |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
585 else |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
586 // When the actual type is list<any> or dict<any> go through the values |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
587 // to possibly get a more specific type. |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
588 actual_type = typval2type(actual_tv, get_copyID(), &type_list, |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
589 TVTT_DO_MEMBER | TVTT_MORE_SPECIFIC); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 if (actual_type != NULL) |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
591 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
592 res = check_type_maybe(expected, actual_type, TRUE, where); |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
593 if (res == MAYBE && !(actual_type->tt_type == VAR_FUNC |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
594 && actual_type->tt_member == &t_unknown)) |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
595 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
596 // If a type check is needed that means assigning "any" or |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
597 // "unknown" to a more specific type, which fails here. |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
598 // Execpt when it looks like a lambda, since they have an |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
599 // incomplete type. |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
600 type_mismatch_where(expected, actual_type, where); |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
601 res = FAIL; |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
602 } |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
603 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 clear_type_list(&type_list); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 return res; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 void |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
609 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:
23888
diff
changeset
|
610 { |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
611 where_T where = WHERE_INIT; |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
612 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
613 where.wt_index = arg_idx; |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
614 type_mismatch_where(expected, actual, where); |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
615 } |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
616 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
617 void |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
618 type_mismatch_where(type_T *expected, type_T *actual, where_T where) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 char *tofree1, *tofree2; |
22004
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
621 char *typename1 = type_name(expected, &tofree1); |
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
622 char *typename2 = type_name(actual, &tofree2); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
624 if (where.wt_index > 0) |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
625 { |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
626 if (where.wt_func_name == NULL) |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
627 semsg(_(where.wt_variable |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
628 ? e_variable_nr_type_mismatch_expected_str_but_got_str |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
629 : e_argument_nr_type_mismatch_expected_str_but_got_str), |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
630 where.wt_index, typename1, typename2); |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
631 else |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
632 semsg(_(where.wt_variable |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
633 ? e_variable_nr_type_mismatch_expected_str_but_got_str_in_str |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
634 : e_argument_nr_type_mismatch_expected_str_but_got_str_in_str), |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
635 where.wt_index, typename1, typename2, where.wt_func_name); |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
636 } |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
637 else if (where.wt_func_name == NULL) |
22004
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
638 semsg(_(e_type_mismatch_expected_str_but_got_str), |
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
639 typename1, typename2); |
25326
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
640 else |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
641 semsg(_(e_type_mismatch_expected_str_but_got_str_in_str), |
cfbf40f749b0
patch 8.2.3200: Vim9: hard to guess where a type error is given
Bram Moolenaar <Bram@vim.org>
parents:
25196
diff
changeset
|
642 typename1, typename2, where.wt_func_name); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 vim_free(tofree1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 vim_free(tofree2); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 * Check if the expected and actual types match. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 * Does not allow for assigning "any" to a specific type. |
22004
a9e60176dcd3
patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents:
21909
diff
changeset
|
650 * When "argidx" > 0 it is included in the error message. |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
651 * Return OK if types match. |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
652 * Return FAIL if types do not match. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 int |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
655 check_type( |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
656 type_T *expected, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
657 type_T *actual, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
658 int give_msg, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
659 where_T where) |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
660 { |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
661 int ret = check_type_maybe(expected, actual, give_msg, where); |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
662 |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
663 return ret == MAYBE ? OK : ret; |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
664 } |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
665 |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
666 /* |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
667 * As check_type() but return MAYBE when a runtime type check should be used |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
668 * when compiling. |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
669 */ |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
670 int |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
671 check_type_maybe( |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
672 type_T *expected, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
673 type_T *actual, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
674 int give_msg, |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
675 where_T where) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 int ret = OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 // When expected is "unknown" we accept any actual type. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 // When expected is "any" we accept any actual type except "void". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 if (expected->tt_type != VAR_UNKNOWN |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID)) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 { |
22347
712bc35842aa
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents:
22322
diff
changeset
|
685 // tt_type should match, except that a "partial" can be assigned to a |
712bc35842aa
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents:
22322
diff
changeset
|
686 // variable with type "func". |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
687 // And "unknown" (using global variable) and "any" need a runtime type |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
688 // check. |
22347
712bc35842aa
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents:
22322
diff
changeset
|
689 if (!(expected->tt_type == actual->tt_type |
26678
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
690 || actual->tt_type == VAR_UNKNOWN |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
691 || actual->tt_type == VAR_ANY |
22347
712bc35842aa
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents:
22322
diff
changeset
|
692 || (expected->tt_type == VAR_FUNC |
712bc35842aa
patch 8.2.1722: Vim9: cannot assign a lambda to a variable of type function
Bram Moolenaar <Bram@vim.org>
parents:
22322
diff
changeset
|
693 && actual->tt_type == VAR_PARTIAL))) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 { |
22202
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
695 if (expected->tt_type == VAR_BOOL |
22184
2463b3d89ce2
patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents:
22004
diff
changeset
|
696 && (actual->tt_flags & TTFLAG_BOOL_OK)) |
2463b3d89ce2
patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents:
22004
diff
changeset
|
697 // Using number 0 or 1 for bool is OK. |
2463b3d89ce2
patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents:
22004
diff
changeset
|
698 return OK; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 if (give_msg) |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
700 type_mismatch_where(expected, actual, where); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 // "unknown" is used for an empty list or dict |
26678
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
706 if (actual->tt_member != NULL && actual->tt_member != &t_unknown) |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
707 ret = check_type_maybe(expected->tt_member, actual->tt_member, |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
708 FALSE, where); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 } |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
710 else if (expected->tt_type == VAR_FUNC && actual != &t_any) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 { |
23418
681f042ae5ac
patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
712 // If the return type is unknown it can be anything, including |
681f042ae5ac
patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents:
23362
diff
changeset
|
713 // nothing, thus there is no point in checking. |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
714 if (expected->tt_member != &t_unknown) |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
715 { |
26678
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
716 if (actual->tt_member != NULL |
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
717 && actual->tt_member != &t_unknown) |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
718 ret = check_type_maybe(expected->tt_member, |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
719 actual->tt_member, FALSE, where); |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
720 else |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
721 ret = MAYBE; |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
722 } |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
723 if (ret != FAIL && expected->tt_argcount != -1 |
25135
5731bcaaabcb
patch 8.2.3104: Vim9: unspecified function type causes type error
Bram Moolenaar <Bram@vim.org>
parents:
25126
diff
changeset
|
724 && actual->tt_min_argcount != -1 |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
725 && (actual->tt_argcount == -1 |
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
726 || (actual->tt_argcount < expected->tt_min_argcount |
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
727 || actual->tt_argcount > expected->tt_argcount))) |
23481
62fe9a7fd582
patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
728 ret = FAIL; |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
729 if (ret != FAIL && expected->tt_args != NULL |
23481
62fe9a7fd582
patch 8.2.2283: Vim9: crash when lambda has fewer arguments than expected
Bram Moolenaar <Bram@vim.org>
parents:
23418
diff
changeset
|
730 && actual->tt_args != NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 for (i = 0; i < expected->tt_argcount; ++i) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 // Allow for using "any" argument type, lambda's have them. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 if (actual->tt_args[i] != &t_any && check_type( |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
737 expected->tt_args[i], actual->tt_args[i], FALSE, |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
738 where) == FAIL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 ret = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 } |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
744 if (ret == OK && expected->tt_argcount >= 0 |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
745 && actual->tt_argcount == -1) |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
746 // check the argument count at runtime |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
747 ret = MAYBE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 if (ret == FAIL && give_msg) |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
750 type_mismatch_where(expected, actual, where); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 } |
26630
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
752 |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
753 if (ret == OK && expected->tt_type != VAR_UNKNOWN |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
754 && expected->tt_type != VAR_ANY |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
755 && (actual->tt_type == VAR_UNKNOWN || actual->tt_type == VAR_ANY)) |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
756 // check the type at runtime |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
757 ret = MAYBE; |
57bc1001160b
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
758 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 return ret; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 /* |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
763 * Check that the arguments of "type" match "argvars[argcount]". |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
764 * "base_tv" is from "expr->Func()". |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
765 * Return OK/FAIL. |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
766 */ |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
767 int |
23640
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
768 check_argument_types( |
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
769 type_T *type, |
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
770 typval_T *argvars, |
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
771 int argcount, |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
772 typval_T *base_tv, |
23640
8dcb2255ff9a
patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents:
23594
diff
changeset
|
773 char_u *name) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
774 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
775 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
776 int i; |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
777 int totcount = argcount + (base_tv == NULL ? 0 : 1); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
778 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
779 if (type->tt_type != VAR_FUNC && type->tt_type != VAR_PARTIAL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
780 return OK; // just in case |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
781 if (totcount < type->tt_min_argcount - varargs) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
782 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
783 emsg_funcname(e_not_enough_arguments_for_function_str, name); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
784 return FAIL; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
785 } |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
786 if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
787 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
788 emsg_funcname(e_too_many_arguments_for_function_str, name); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
789 return FAIL; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
790 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
791 if (type->tt_args == NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
792 return OK; // cannot check |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
793 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
794 |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
795 for (i = 0; i < totcount; ++i) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
796 { |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
797 type_T *expected; |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
798 typval_T *tv; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
799 |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
800 if (base_tv != NULL) |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
801 { |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
802 if (i == 0) |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
803 tv = base_tv; |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
804 else |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
805 tv = &argvars[i - 1]; |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
806 } |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
807 else |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
808 tv = &argvars[i]; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
809 if (varargs && i >= type->tt_argcount - 1) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
810 expected = type->tt_args[type->tt_argcount - 1]->tt_member; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
811 else |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
812 expected = type->tt_args[i]; |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
813 if (check_typval_arg_type(expected, tv, NULL, i + 1) == FAIL) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
814 return FAIL; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
815 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
816 return OK; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
817 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
818 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
819 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 * Skip over a type definition and return a pointer to just after it. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 * When "optional" is TRUE then a leading "?" is accepted. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 char_u * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 skip_type(char_u *start, int optional) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 char_u *p = start; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 if (optional && *p == '?') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 while (ASCII_ISALNUM(*p) || *p == '_') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 // Skip over "<type>"; this is permissive about white space. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 if (*skipwhite(p) == '<') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 p = skip_type(skipwhite(p + 1), FALSE); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 if (*p == '>') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 else if ((*p == '(' || (*p == ':' && VIM_ISWHITE(p[1]))) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 && STRNCMP("func", start, 4) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 if (*p == '(') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 // handle func(args): type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 while (*p != ')' && *p != NUL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 char_u *sp = p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 if (STRNCMP(p, "...", 3) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 p += 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 p = skip_type(p, TRUE); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 if (p == sp) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 return p; // syntax error |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 if (*p == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 p = skipwhite(p + 1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 if (*p == ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 if (p[1] == ':') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 p = skip_type(skipwhite(p + 2), FALSE); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 // handle func: return_type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 p = skip_type(skipwhite(p + 1), FALSE); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 return p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 * Parse the member type: "<type>" and return "type" with the member set. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 * Use "type_gap" if a new type needs to be added. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 * Returns NULL in case of failure. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 static type_T * |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
885 parse_type_member( |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
886 char_u **arg, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
887 type_T *type, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
888 garray_T *type_gap, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
889 int give_error) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 type_T *member_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 int prev_called_emsg = called_emsg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 if (**arg != '<') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
896 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
897 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
898 if (*skipwhite(*arg) == '<') |
23888
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
899 semsg(_(e_no_white_space_allowed_before_str_str), "<", *arg); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
900 else |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
901 emsg(_(e_missing_type)); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
902 } |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
903 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 *arg = skipwhite(*arg + 1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
907 member_type = parse_type(arg, type_gap, give_error); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
908 if (member_type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
909 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 *arg = skipwhite(*arg); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 if (**arg != '>' && called_emsg == prev_called_emsg) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
914 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
915 emsg(_(e_missing_gt_after_type)); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
916 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 if (type->tt_type == VAR_LIST) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 return get_list_type(member_type, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 return get_dict_type(member_type, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 * Parse a type at "arg" and advance over it. |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
927 * When "give_error" is TRUE give error messages, otherwise be quiet. |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
928 * Return NULL for failure. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 type_T * |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
931 parse_type(char_u **arg, garray_T *type_gap, int give_error) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 char_u *p = *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 size_t len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 // skip over the first word |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 while (ASCII_ISALNUM(*p) || *p == '_') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 len = p - *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 switch (**arg) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 case 'a': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 if (len == 3 && STRNCMP(*arg, "any", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 case 'b': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 if (len == 4 && STRNCMP(*arg, "bool", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 return &t_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 if (len == 4 && STRNCMP(*arg, "blob", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 return &t_blob; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 case 'c': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 if (len == 7 && STRNCMP(*arg, "channel", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 return &t_channel; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 case 'd': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 if (len == 4 && STRNCMP(*arg, "dict", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
973 return parse_type_member(arg, &t_dict_any, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
974 type_gap, give_error); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 case 'f': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 if (len == 5 && STRNCMP(*arg, "float", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 #ifdef FEAT_FLOAT |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 return &t_float; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 #else |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
984 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
985 emsg(_(e_this_vim_is_not_compiled_with_float_support)); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
986 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 #endif |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 if (len == 4 && STRNCMP(*arg, "func", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 type_T *ret_type = &t_unknown; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 int argcount = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 int flags = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 int first_optional = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 type_T *arg_type[MAX_FUNC_ARGS + 1]; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 // func({type}, ...{type}): {type} |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 if (**arg == '(') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 // "func" may or may not return a value, "func()" does |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 // not return a value. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 ret_type = &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 p = ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 while (*p != NUL && *p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 if (*p == '?') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 if (first_optional == -1) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 first_optional = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 else if (STRNCMP(p, "...", 3) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 flags |= TTFLAG_VARARGS; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 p += 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 else if (first_optional != -1) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1023 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1024 emsg(_(e_mandatory_argument_after_optional_argument)); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1025 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1028 type = parse_type(&p, type_gap, give_error); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1029 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1030 return NULL; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1031 arg_type[argcount++] = type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 // Nothing comes after "...{type}". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 if (flags & TTFLAG_VARARGS) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 if (*p != ',' && *skipwhite(p) == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1039 if (give_error) |
23888
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1040 semsg(_(e_no_white_space_allowed_before_str_str), |
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
1041 ",", p); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1042 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 if (*p == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (!VIM_ISWHITE(*p)) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1049 if (give_error) |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
1050 semsg(_(e_white_space_required_after_str_str), |
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
1051 ",", p - 1); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1052 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 if (argcount == MAX_FUNC_ARGS) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1058 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1059 emsg(_(e_too_many_argument_types)); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1060 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 if (*p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1067 if (give_error) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25788
diff
changeset
|
1068 emsg(_(e_missing_closing_paren)); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1069 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 *arg = p + 1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 if (**arg == ':') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 // parse return type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 ++*arg; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1077 if (!VIM_ISWHITE(**arg) && give_error) |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
1078 semsg(_(e_white_space_required_after_str_str), |
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
1079 ":", *arg - 1); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 *arg = skipwhite(*arg); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1081 ret_type = parse_type(arg, type_gap, give_error); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1082 if (ret_type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1083 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 if (flags == 0 && first_optional == -1 && argcount <= 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 type = get_func_type(ret_type, argcount, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 type = alloc_func_type(ret_type, argcount, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 type->tt_flags = flags; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 if (argcount > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 type->tt_argcount = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 type->tt_min_argcount = first_optional == -1 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 ? argcount : first_optional; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 if (func_type_add_arg_types(type, argcount, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 type_gap) == FAIL) |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1098 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 mch_memmove(type->tt_args, arg_type, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 sizeof(type_T *) * argcount); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 case 'j': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 if (len == 3 && STRNCMP(*arg, "job", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 return &t_job; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 case 'l': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 if (len == 4 && STRNCMP(*arg, "list", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1117 return parse_type_member(arg, &t_list_any, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1118 type_gap, give_error); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 case 'n': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 if (len == 6 && STRNCMP(*arg, "number", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 case 's': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 if (len == 6 && STRNCMP(*arg, "string", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 return &t_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 case 'v': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 if (len == 4 && STRNCMP(*arg, "void", len) == 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 return &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1144 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1145 semsg(_(e_type_not_recognized_str), *arg); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1146 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 * Check if "type1" and "type2" are exactly the same. |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1151 * "flags" can have ETYPE_ARG_UNKNOWN, which means that an unknown argument |
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1152 * type in "type1" is accepted. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 */ |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23338
diff
changeset
|
1154 int |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1155 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
|
1156 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 |
24118
1027495445bc
patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
1159 if (type1 == NULL || type2 == NULL) |
1027495445bc
patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
1160 return FALSE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 if (type1->tt_type != type2->tt_type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 switch (type1->tt_type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 case VAR_UNKNOWN: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 case VAR_ANY: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 case VAR_VOID: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 case VAR_SPECIAL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 case VAR_BOOL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 case VAR_NUMBER: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 case VAR_FLOAT: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 case VAR_STRING: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 case VAR_BLOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 case VAR_JOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 case VAR_CHANNEL: |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24438
diff
changeset
|
1176 case VAR_INSTR: |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 break; // not composite is always OK |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 case VAR_LIST: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 case VAR_DICT: |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1180 return equal_type(type1->tt_member, type2->tt_member, flags); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 case VAR_PARTIAL: |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1183 if (!equal_type(type1->tt_member, type2->tt_member, flags) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 || type1->tt_argcount != type2->tt_argcount) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 if (type1->tt_argcount < 0 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 || type1->tt_args == NULL || type2->tt_args == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 for (i = 0; i < type1->tt_argcount; ++i) |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1190 if ((flags & ETYPE_ARG_UNKNOWN) == 0 |
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1191 && !equal_type(type1->tt_args[i], type2->tt_args[i], |
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1192 flags)) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 * Find the common type of "type1" and "type2" and put it in "dest". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 * "type2" and "dest" may be the same. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 void |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 { |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1206 if (equal_type(type1, type2, 0)) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 *dest = type1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1212 // If either is VAR_UNKNOWN use the other type. An empty list/dict has no |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1213 // specific type. |
24118
1027495445bc
patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
1214 if (type1 == NULL || type1->tt_type == VAR_UNKNOWN) |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1215 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1216 *dest = type2; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1217 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1218 } |
24118
1027495445bc
patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents:
23917
diff
changeset
|
1219 if (type2 == NULL || type2->tt_type == VAR_UNKNOWN) |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1220 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1221 *dest = type1; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1222 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1223 } |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1224 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1225 if (type1->tt_type == type2->tt_type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 common_type(type1->tt_member, type2->tt_member, &common, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 if (type1->tt_type == VAR_LIST) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 *dest = get_list_type(common, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1235 *dest = get_dict_type(common, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 if (type1->tt_type == VAR_FUNC) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 |
28059
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1242 // When one of the types is t_func_unknown return the other one. |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1243 // Useful if a list or dict item is null_func. |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1244 if (type1 == &t_func_unknown) |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1245 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1246 *dest = type2; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1247 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1248 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1249 if (type2 == &t_func_unknown) |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1250 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1251 *dest = type1; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1252 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1253 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1254 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 common_type(type1->tt_member, type2->tt_member, &common, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 if (type1->tt_argcount == type2->tt_argcount |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1257 && type1->tt_argcount >= 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 int argcount = type1->tt_argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1262 *dest = alloc_func_type(common, argcount, type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 if (type1->tt_args != NULL && type2->tt_args != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1264 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1265 if (func_type_add_arg_types(*dest, argcount, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 type_gap) == OK) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 for (i = 0; i < argcount; ++i) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 common_type(type1->tt_args[i], type2->tt_args[i], |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 &(*dest)->tt_args[i], type_gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 else |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
1273 // Use -1 for "tt_argcount" to indicate an unknown number of |
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
1274 // arguments. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 *dest = alloc_func_type(common, -1, type_gap); |
25126
b825efff9790
patch 8.2.3100: Vim9: no error when using type with unknown number of args
Bram Moolenaar <Bram@vim.org>
parents:
24996
diff
changeset
|
1276 |
22492
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1277 // Use the minimum of min_argcount. |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1278 (*dest)->tt_min_argcount = |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1279 type1->tt_min_argcount < type2->tt_min_argcount |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1280 ? type1->tt_min_argcount : type2->tt_min_argcount; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1282 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 *dest = &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1288 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1289 * Push an entry onto the type stack. "type" used both for the current type |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1290 * and the declared type. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1291 * Returns FAIL when out of memory. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1292 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1293 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1294 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:
26925
diff
changeset
|
1295 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1296 return push_type_stack2(cctx, type, type); |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1297 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1298 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1299 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1300 * Push an entry onto the type stack. "type" is the current type, "decl_type" |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1301 * is the declared type. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1302 * Returns FAIL when out of memory. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1303 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1304 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1305 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:
26925
diff
changeset
|
1306 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1307 garray_T *stack = &cctx->ctx_type_stack; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1308 type2_T *typep; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1309 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1310 if (GA_GROW_FAILS(stack, 1)) |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1311 return FAIL; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1312 typep = ((type2_T *)stack->ga_data) + stack->ga_len; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1313 typep->type_curr = type; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1314 typep->type_decl = decl_type; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1315 ++stack->ga_len; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1316 return OK; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1317 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1318 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1319 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1320 * Set the type of the top of the stack to "type". |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1321 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1322 void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1323 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:
26925
diff
changeset
|
1324 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1325 garray_T *stack = &cctx->ctx_type_stack; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1326 type2_T *typep = ((type2_T *)stack->ga_data) |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1327 + stack->ga_len - 1 - offset; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1328 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1329 typep->type_curr = type; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1330 typep->type_decl = &t_any; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1331 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1332 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1333 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1334 * Get the current type from the type stack. If "offset" is zero the one at |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1335 * the top, |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1336 * if "offset" is one the type above that, etc. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1337 * Returns &t_unknown if there is no such stack entry. |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1338 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1339 type_T * |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1340 get_type_on_stack(cctx_T *cctx, int offset) |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1341 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1342 garray_T *stack = &cctx->ctx_type_stack; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1343 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1344 if (offset + 1 > stack->ga_len) |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1345 return &t_unknown; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1346 return (((type2_T *)stack->ga_data) + stack->ga_len - offset - 1) |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1347 ->type_curr; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1348 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1349 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1350 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1351 * Get the declared type from the type stack. If "offset" is zero the one at |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1352 * the top, |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1353 * if "offset" is one the type above that, etc. |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1354 * Returns &t_unknown if there is no such stack entry. |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1355 */ |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1356 type_T * |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1357 get_decl_type_on_stack(cctx_T *cctx, int offset) |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1358 { |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1359 garray_T *stack = &cctx->ctx_type_stack; |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1360 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1361 if (offset + 1 > stack->ga_len) |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1362 return &t_unknown; |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1363 return (((type2_T *)stack->ga_data) + stack->ga_len - offset - 1) |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1364 ->type_decl; |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1365 } |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1366 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1367 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1368 * Get the member type of a dict or list from the items on the stack of "cctx". |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1369 * The declared type is stored in "decl_type". |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1370 * For a list "skip" is 1, for a dict "skip" is 2, keys are skipped. |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1371 * Returns &t_void for an empty list or dict. |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1372 * Otherwise finds the common type of all items. |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1373 */ |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1374 type_T * |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1375 get_member_type_from_stack( |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1376 int count, |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1377 int skip, |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1378 cctx_T *cctx) |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1379 { |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1380 garray_T *stack = &cctx->ctx_type_stack; |
26939
ae2324aca26b
patch 8.2.3998: asan error for adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents:
26935
diff
changeset
|
1381 type2_T *typep; |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1382 garray_T *type_gap = cctx->ctx_type_list; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1383 int i; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1384 type_T *result; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1385 type_T *type; |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1386 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1387 // Use "unknown" for an empty list or dict. |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1388 if (count == 0) |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1389 return &t_unknown; |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1390 |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1391 // Use the first value type for the list member type, then find the common |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1392 // type from following items. |
26939
ae2324aca26b
patch 8.2.3998: asan error for adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents:
26935
diff
changeset
|
1393 typep = ((type2_T *)stack->ga_data) + stack->ga_len; |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1394 result = (typep -(count * skip) + skip - 1)->type_curr; |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1395 for (i = 1; i < count; ++i) |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1396 { |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1397 if (result == &t_any) |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1398 break; // won't get more common |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1399 type = (typep -((count - i) * skip) + skip - 1)->type_curr; |
21715
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1400 common_type(type, result, &result, type_gap); |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1401 } |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1402 |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1403 return result; |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1404 } |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1405 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 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
|
1408 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 switch (type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 case VAR_UNKNOWN: break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 case VAR_ANY: return "any"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 case VAR_VOID: return "void"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 case VAR_SPECIAL: return "special"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 case VAR_BOOL: return "bool"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 case VAR_NUMBER: return "number"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 case VAR_FLOAT: return "float"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 case VAR_STRING: return "string"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 case VAR_BLOB: return "blob"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 case VAR_JOB: return "job"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 case VAR_CHANNEL: return "channel"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 case VAR_LIST: return "list"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 case VAR_DICT: return "dict"; |
24606
a4fda40e0bb9
patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
24438
diff
changeset
|
1424 case VAR_INSTR: return "instr"; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 case VAR_PARTIAL: return "func"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 return "unknown"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 * Return the name of a type. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 * The result may be in allocated memory, in which case "tofree" is set. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 type_name(type_T *type, char **tofree) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1439 char *name; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 *tofree = NULL; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1442 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1443 return "[unknown]"; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1444 name = vartype_name(type->tt_type); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 if (type->tt_type == VAR_LIST || type->tt_type == VAR_DICT) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 char *member_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 char *member_name = type_name(type->tt_member, &member_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 size_t len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 len = STRLEN(name) + STRLEN(member_name) + 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 *tofree = alloc(len); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 if (*tofree != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 vim_snprintf(*tofree, len, "%s<%s>", name, member_name); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 vim_free(member_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 return *tofree; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 if (type->tt_type == VAR_FUNC) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 garray_T ga; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 ga_init2(&ga, 1, 100); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 if (ga_grow(&ga, 20) == FAIL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 return "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 STRCPY(ga.ga_data, "func("); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 ga.ga_len += 5; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 for (i = 0; i < type->tt_argcount; ++i) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 { |
25196
694f114a7673
patch 8.2.3134: crash when using typename() on a function reference
Bram Moolenaar <Bram@vim.org>
parents:
25137
diff
changeset
|
1474 char *arg_free = NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 char *arg_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 if (type->tt_args == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 arg_type = "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 arg_type = type_name(type->tt_args[i], &arg_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 if (i > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 STRCPY((char *)ga.ga_data + ga.ga_len, ", "); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 ga.ga_len += 2; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 len = (int)STRLEN(arg_type); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 if (ga_grow(&ga, len + 8) == FAIL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 vim_free(arg_free); |
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
|
1491 ga_clear(&ga); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 return "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 if (varargs && i == type->tt_argcount - 1) |
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
|
1495 ga_concat(&ga, (char_u *)"..."); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 else if (i >= type->tt_min_argcount) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 *((char *)ga.ga_data + ga.ga_len++) = '?'; |
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
|
1498 ga_concat(&ga, (char_u *)arg_type); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 vim_free(arg_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 } |
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
|
1501 if (type->tt_argcount < 0) |
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
|
1502 // any number of arguments |
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
|
1503 ga_concat(&ga, (char_u *)"..."); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1505 if (type->tt_member == &t_void) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1506 STRCPY((char *)ga.ga_data + ga.ga_len, ")"); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 char *ret_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1510 char *ret_name = type_name(type->tt_member, &ret_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1513 len = (int)STRLEN(ret_name) + 4; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1514 if (ga_grow(&ga, len) == FAIL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1516 vim_free(ret_free); |
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
|
1517 ga_clear(&ga); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 return "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1519 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1520 STRCPY((char *)ga.ga_data + ga.ga_len, "): "); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1521 STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1522 vim_free(ret_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1523 } |
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
|
1524 *tofree = ga.ga_data; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 return ga.ga_data; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1527 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 return name; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1530 |
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
|
1531 /* |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1532 * "typename(expr)" function |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1533 */ |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1534 void |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1535 f_typename(typval_T *argvars, typval_T *rettv) |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1536 { |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1537 garray_T type_list; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1538 type_T *type; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1539 char *tofree; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1540 char *name; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1541 |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1542 rettv->v_type = VAR_STRING; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1543 ga_init2(&type_list, sizeof(type_T *), 10); |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
1544 type = typval2type(argvars, get_copyID(), &type_list, TVTT_DO_MEMBER); |
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
|
1545 name = type_name(type, &tofree); |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1546 if (tofree != NULL) |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1547 rettv->vval.v_string = (char_u *)tofree; |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1548 else |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1549 { |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1550 rettv->vval.v_string = vim_strsave((char_u *)name); |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1551 vim_free(tofree); |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1552 } |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1553 clear_type_list(&type_list); |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1554 } |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1555 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 #endif // FEAT_EVAL |