Mercurial > vim
annotate src/vim9type.c @ 29800:ae63d041243b v9.0.0239
patch 9.0.0239: build failure without the +wildmenu feature
Commit: https://github.com/vim/vim/commit/8884916043a4d517ff1cf3afb8c8a424a8ef3610
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 21 19:08:50 2022 +0100
patch 9.0.0239: build failure without the +wildmenu feature
Problem: Build failure without the +wildmenu feature.
Solution: Move parenthesis.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 21 Aug 2022 20:15:03 +0200 |
parents | 9f8dd1b77563 |
children | d751e924cc29 |
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". |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
247 * "argcount" must be -1 or 0, a predefined type can be used. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 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
|
251 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 // recognize commonly used types |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
253 if (ret_type == &t_unknown || ret_type == NULL) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
254 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
255 // (argcount == 0) is not possible |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
256 return &t_func_unknown; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
257 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
258 if (ret_type == &t_void) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
259 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
260 if (argcount == 0) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
261 return &t_func_0_void; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
262 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
263 return &t_func_void; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
264 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
265 if (ret_type == &t_any) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 { |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
267 if (argcount == 0) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
268 return &t_func_0_any; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
269 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
270 return &t_func_any; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
271 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
272 if (ret_type == &t_number) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
273 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
274 if (argcount == 0) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
275 return &t_func_0_number; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
276 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
277 return &t_func_number; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
278 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
279 if (ret_type == &t_string) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
280 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
281 if (argcount == 0) |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
282 return &t_func_0_string; |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
283 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
284 return &t_func_string; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 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
|
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 * 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
|
292 * vararg). |
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 int |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 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
|
296 type_T *functype, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 int argcount, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 garray_T *type_gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 // 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
|
301 // pointer to type_gap. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 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
|
303 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 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
|
305 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
|
306 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 ((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
|
308 (void *)functype->tt_args; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 ++type_gap->ga_len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 return OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
311 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
312 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 * 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
|
315 * "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
|
316 * 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
|
317 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
318 * 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
|
319 * is "any". |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 */ |
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
|
321 static type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
322 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
|
323 { |
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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 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
|
330 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 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
|
332 return &t_bool; |
21711
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_STRING) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 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
|
335 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
|
336 { |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 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
|
343 { |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
344 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
|
345 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
|
346 |
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
|
347 // 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
|
348 // 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
|
349 // 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
|
350 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
|
351 && (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
|
352 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
|
353 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
|
354 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
|
355 // 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
|
356 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
357 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
|
358 || (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
|
359 || 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
|
360 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
|
361 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
|
362 return &t_list_number; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
363 if (l->lv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
364 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
365 return &t_list_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
366 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
|
367 |
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
|
368 // 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 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
|
379 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 dict_iterator_T iter; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 typval_T *value; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
382 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
|
383 |
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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 // 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
|
389 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
390 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
|
391 || (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
|
392 || 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
|
393 return d->dv_type; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
394 if (d->dv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
395 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
396 return &t_dict_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
397 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
|
398 |
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
|
399 // 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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 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
|
410 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 char_u *name = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 ufunc_T *ufunc = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 |
25692
17830c066d4b
patch 8.2.3382: crash when getting the type of a NULL partial
Bram Moolenaar <Bram@vim.org>
parents:
25646
diff
changeset
|
414 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
|
415 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 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
|
417 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
|
418 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 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
|
420 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 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
|
426 { |
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
|
427 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
|
428 |
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
|
429 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
|
430 { |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
431 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
|
432 |
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
|
433 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
|
434 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
|
435 } |
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
|
436 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
|
437 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
|
438 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 if (ufunc != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 // 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
|
442 // compiling the function. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 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
|
444 && 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
|
445 == FAIL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 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
|
450 { |
27010
b049c3b63a67
patch 8.2.4034: Coverity warns for possibly using a NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
26939
diff
changeset
|
451 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
|
452 && 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
|
453 { |
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 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
|
455 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
|
456 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
|
457 *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
|
458 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
|
459 { |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 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
|
464 else |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
465 { |
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
466 int i; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
467 |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 } |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
474 } |
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
|
475 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
|
476 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 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
|
478 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 |
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
|
482 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
|
483 if (type == NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 && 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
|
490 { |
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
491 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
|
492 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
|
493 } |
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
|
494 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
|
495 |
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
|
496 return type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 /* |
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
|
500 * 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
|
501 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
502 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
|
503 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
|
504 { |
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 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
|
506 && (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
|
507 && (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
|
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 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
510 /* |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
511 * 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
|
512 * "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
|
513 * 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
|
514 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
515 * 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
|
516 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
517 type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
518 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
|
519 { |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
520 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
|
521 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
522 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
|
523 && (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
|
524 && (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
|
525 // 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
|
526 // bool. |
4b4f695e9cd1
patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
527 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
|
528 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
|
529 } |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
530 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
531 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 * 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
|
533 * "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
|
534 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 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
|
537 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 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
|
539 return &t_list_string; |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
540 if (tv->v_type == VAR_DICT) // e.g. for v:event |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 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
|
542 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
|
543 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 { |
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
|
552 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
|
553 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 * 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
|
561 * 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
|
562 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 int |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
564 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
|
565 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 garray_T type_list; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 type_T *actual_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 int res = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
570 if (expected == NULL) |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
571 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
|
572 // |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
573 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
|
574 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
575 // 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
|
576 // 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
|
577 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
|
578 || (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
|
579 && 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
|
580 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
|
581 else |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
582 // 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
|
583 // 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
|
584 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
|
585 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
|
586 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
|
587 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
588 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
|
589 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
|
590 && 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
|
591 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
592 // 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
|
593 // "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
|
594 // 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
|
595 // incomplete type. |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
596 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
|
597 res = FAIL; |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
598 } |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
599 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 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
|
601 return res; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 void |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
605 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
|
606 { |
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
|
607 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
|
608 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
609 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
|
610 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
|
611 } |
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 void |
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(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
|
615 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
620 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
|
621 { |
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
|
622 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
|
623 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
|
624 ? 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
|
625 : 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
|
626 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
|
627 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
|
628 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
|
629 ? 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
|
630 : 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
|
631 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
|
632 } |
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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 vim_free(tofree1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 vim_free(tofree2); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 * 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
|
645 * 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
|
646 * 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
|
647 * 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
|
648 * 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
|
649 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 { |
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 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
|
658 |
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 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
|
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 |
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 * 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
|
664 * 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
|
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 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 where_T where) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 int ret = OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 // 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
|
676 // 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
|
677 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
|
678 && !(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
|
679 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 { |
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
|
681 // 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
|
682 // 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
|
683 // 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
|
684 // 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
|
685 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
|
686 || 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
|
687 || 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
|
688 || (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
|
689 && 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
|
690 { |
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
|
691 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
|
692 && (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
|
693 // 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
|
694 return OK; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 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
|
696 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
|
697 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 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
|
700 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 // "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
|
702 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
|
703 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
|
704 FALSE, where); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 } |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
706 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
|
707 { |
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
|
708 // 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
|
709 // 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
|
710 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
|
711 { |
26678
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
712 if (actual->tt_member != NULL |
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
713 && 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 } |
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
|
719 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
|
720 && 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
|
721 && (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
|
722 || (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
|
723 || 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
|
724 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
|
725 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
|
726 && 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
|
727 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 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
|
731 // 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
|
732 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
|
733 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
|
734 where) == FAIL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 ret = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 } |
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
|
740 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
|
741 && 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
|
742 // 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
|
743 ret = MAYBE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 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
|
746 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
|
747 } |
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
|
748 |
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
|
749 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
|
750 && 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
|
751 && (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
|
752 // 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
|
753 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
|
754 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 return ret; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 /* |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
759 * 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
|
760 * "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
|
761 * 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
|
762 */ |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
771 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
|
772 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
|
773 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
|
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 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
|
776 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
|
777 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
|
778 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
779 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
|
780 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
|
781 } |
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
|
782 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
|
783 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
784 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
|
785 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
|
786 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
787 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
|
788 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
|
789 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
790 |
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
|
791 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
|
792 { |
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
|
793 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
|
794 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
|
795 |
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
|
796 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
|
797 { |
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 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
|
799 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
|
800 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
|
801 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
|
802 } |
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 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
|
804 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
|
805 if (varargs && i >= type->tt_argcount - 1) |
28952
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
806 { |
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
807 expected = type->tt_args[type->tt_argcount - 1]; |
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
808 if (expected != NULL) |
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
809 expected = expected->tt_member; |
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
810 } |
23527
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. |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
882 * "info" is extra information for an error message. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 * 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
|
884 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 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
|
886 parse_type_member( |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
887 char_u **arg, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
888 type_T *type, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
889 garray_T *type_gap, |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
890 int give_error, |
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
891 char *info) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 { |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
893 char_u *arg_start = *arg; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 type_T *member_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 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
|
896 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 if (**arg != '<') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
899 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
900 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
901 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
|
902 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
|
903 else |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
904 semsg(_(e_missing_type_after_str), info); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
905 } |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
906 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 *arg = skipwhite(*arg + 1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
910 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
|
911 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
|
912 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 *arg = skipwhite(*arg); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 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
|
916 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
917 if (give_error) |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
918 semsg(_(e_missing_gt_after_type_str), arg_start); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
919 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 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
|
924 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
|
925 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
|
926 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 * 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
|
930 * 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
|
931 * 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
|
932 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 type_T * |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
934 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
|
935 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 char_u *p = *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 size_t len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 // 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
|
940 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
|
941 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 len = p - *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 switch (**arg) |
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 case 'a': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 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
|
948 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 case 'b': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 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
|
955 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 return &t_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 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
|
960 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 return &t_blob; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 case 'c': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 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
|
967 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 return &t_channel; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 case 'd': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 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
|
974 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
976 return parse_type_member(arg, &t_dict_any, |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
977 type_gap, give_error, "dict"); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 case 'f': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 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
|
982 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 #ifdef FEAT_FLOAT |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 return &t_float; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 #else |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
987 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
988 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
|
989 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 #endif |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 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
|
993 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 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
|
996 int argcount = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 int flags = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 int first_optional = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 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
|
1000 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 // func({type}, ...{type}): {type} |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 if (**arg == '(') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 // "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
|
1006 // not return a value. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 ret_type = &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 p = ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 while (*p != NUL && *p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 if (*p == '?') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 if (first_optional == -1) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 first_optional = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 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
|
1020 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 flags |= TTFLAG_VARARGS; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 p += 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 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
|
1025 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1026 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1027 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
|
1028 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1031 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
|
1032 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1033 return NULL; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1034 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
|
1035 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 // Nothing comes after "...{type}". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 if (flags & TTFLAG_VARARGS) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 if (*p != ',' && *skipwhite(p) == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1042 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
|
1043 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
|
1044 ",", p); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1045 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (*p == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 if (!VIM_ISWHITE(*p)) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1052 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
|
1053 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
|
1054 ",", p - 1); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1055 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 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
|
1060 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1061 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1062 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
|
1063 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 if (*p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1070 if (give_error) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25788
diff
changeset
|
1071 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
|
1072 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 *arg = p + 1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 if (**arg == ':') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 // parse return type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 ++*arg; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1080 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
|
1081 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
|
1082 ":", *arg - 1); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 *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
|
1084 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
|
1085 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
|
1086 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 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
|
1089 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
|
1090 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 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
|
1093 type->tt_flags = flags; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 if (argcount > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 type->tt_argcount = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 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
|
1098 ? argcount : first_optional; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 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
|
1100 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
|
1101 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 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
|
1103 sizeof(type_T *) * argcount); |
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 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 case 'j': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 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
|
1111 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 return &t_job; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 case 'l': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 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
|
1118 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1120 return parse_type_member(arg, &t_list_any, |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
1121 type_gap, give_error, "list"); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 case 'n': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 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
|
1126 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 case 's': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 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
|
1133 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 return &t_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 case 'v': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 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
|
1140 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 return &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1146 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1147 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1148 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
|
1149 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 * 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
|
1154 * "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
|
1155 * 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
|
1156 */ |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23338
diff
changeset
|
1157 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
|
1158 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
|
1159 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 |
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
|
1162 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
|
1163 return FALSE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 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
|
1165 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 switch (type1->tt_type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 case VAR_UNKNOWN: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 case VAR_ANY: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 case VAR_VOID: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 case VAR_SPECIAL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 case VAR_BOOL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 case VAR_NUMBER: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 case VAR_FLOAT: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 case VAR_STRING: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 case VAR_BLOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 case VAR_JOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 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
|
1179 case VAR_INSTR: |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 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
|
1181 case VAR_LIST: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 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
|
1183 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
|
1184 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 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
|
1186 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
|
1187 || 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
|
1188 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 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
|
1190 || 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
|
1191 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 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
|
1193 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
|
1194 && !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
|
1195 flags)) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 return TRUE; |
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 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 |
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 * 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
|
1204 * "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
|
1205 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 void |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 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
|
1208 { |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1209 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
|
1210 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 *dest = type1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1215 // 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
|
1216 // 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
|
1217 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
|
1218 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1219 *dest = type2; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1220 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1221 } |
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
|
1222 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
|
1223 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1224 *dest = type1; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1225 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1226 } |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1227 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 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
|
1229 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 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
|
1231 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 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
|
1235 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
|
1236 *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
|
1237 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 *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
|
1239 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 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
|
1242 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 |
28059
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1245 // 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
|
1246 // 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
|
1247 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
|
1248 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1249 *dest = type2; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1250 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1251 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1252 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
|
1253 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1254 *dest = type1; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1255 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1256 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1257 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 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
|
1259 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
|
1260 && type1->tt_argcount >= 0) |
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 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
|
1263 int i; |
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 *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
|
1266 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
|
1267 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 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
|
1269 type_gap) == OK) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 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
|
1271 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
|
1272 &(*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
|
1273 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1275 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
|
1276 // 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
|
1277 // arguments. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 *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
|
1279 |
22492
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1280 // Use the minimum of min_argcount. |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1281 (*dest)->tt_min_argcount = |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1282 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
|
1283 ? 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
|
1284 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 } |
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 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 *dest = &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 |
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
|
1291 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1292 * 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
|
1293 * 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
|
1294 * 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
|
1295 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1296 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1297 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
|
1298 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1299 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
|
1300 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1301 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1302 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1303 * 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
|
1304 * 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
|
1305 * 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
|
1306 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1307 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1308 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
|
1309 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1310 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
|
1311 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
|
1312 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1313 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
|
1314 return FAIL; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 ++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
|
1319 return OK; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1320 } |
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 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1323 * 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
|
1324 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1325 void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1326 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
|
1327 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1328 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
|
1329 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
|
1330 + 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
|
1331 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1332 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
|
1333 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
|
1334 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1335 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1336 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1337 * 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
|
1338 * 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
|
1339 * 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
|
1340 * 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
|
1341 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1342 type_T * |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1343 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
|
1344 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1345 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
|
1346 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1347 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
|
1348 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
|
1349 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
|
1350 ->type_curr; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1351 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1352 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1353 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1354 * 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
|
1355 * 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
|
1356 * 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
|
1357 * 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
|
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 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
|
1360 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
|
1361 { |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1362 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
|
1363 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1364 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
|
1365 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
|
1366 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
|
1367 ->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
|
1368 } |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1369 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1370 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1371 * 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
|
1372 * 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
|
1373 * 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
|
1374 * 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
|
1375 * 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
|
1376 */ |
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 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
|
1378 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
|
1379 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
|
1380 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
|
1381 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
|
1382 { |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1383 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
|
1384 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
|
1385 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
|
1386 int i; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1387 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
|
1388 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
|
1389 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1390 // 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
|
1391 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
|
1392 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
|
1393 |
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
|
1394 // 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
|
1395 // 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
|
1396 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
|
1397 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
|
1398 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
|
1399 { |
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 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
|
1401 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
|
1402 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
|
1403 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
|
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 |
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
|
1406 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
|
1407 } |
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
|
1408 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 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
|
1411 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 switch (type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 case VAR_UNKNOWN: break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 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
|
1416 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
|
1417 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
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 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
|
1425 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
|
1426 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
|
1427 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
|
1428 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 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
|
1431 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 return "unknown"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 |
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 * 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
|
1437 * 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
|
1438 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 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
|
1441 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1442 char *name; |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1443 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
|
1444 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 *tofree = NULL; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1446 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1447 return "[unknown]"; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1448 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
|
1449 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
|
1450 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 char *member_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 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
|
1453 size_t len; |
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 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
|
1456 *tofree = alloc(len); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 if (*tofree != NULL) |
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 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
|
1460 vim_free(member_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 return *tofree; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 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
|
1465 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 garray_T ga; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 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
|
1469 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 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
|
1471 if (ga_grow(&ga, 20) == FAIL) |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1472 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 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
|
1474 ga.ga_len += 5; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 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
|
1477 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 char *arg_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 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
|
1482 arg_type = "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 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
|
1485 if (i > 0) |
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 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
|
1488 ga.ga_len += 2; |
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 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
|
1491 if (ga_grow(&ga, len + 8) == FAIL) |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1492 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 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
|
1494 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
|
1495 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
|
1496 *((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
|
1497 ga_concat(&ga, (char_u *)arg_type); |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1498 VIM_CLEAR(arg_free); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 } |
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
|
1500 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
|
1501 // 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
|
1502 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
|
1503 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 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
|
1505 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
|
1506 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 char *ret_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 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
|
1510 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1511 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1512 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
|
1513 if (ga_grow(&ga, len) == FAIL) |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1514 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1515 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
|
1516 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
|
1517 vim_free(ret_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1518 } |
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
|
1519 *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
|
1520 return ga.ga_data; |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1521 |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1522 failed: |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1523 vim_free(arg_free); |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1524 ga_clear(&ga); |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1525 return "[unknown]"; |
21711
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 |