Mercurial > vim
annotate src/vim9type.c @ 31815:64f03e860c91 v9.0.1240
patch 9.0.1240: cannot access a private object member in a lambda
Commit: https://github.com/vim/vim/commit/62a6923470827acbf124df41134ae6df52f334e6
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 24 15:07:04 2023 +0000
patch 9.0.1240: cannot access a private object member in a lambda
Problem: Cannot access a private object member in a lambda defined inside
the class.
Solution: Go up the context stack to find the class. (closes #11866)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 24 Jan 2023 16:15:07 +0100 |
parents | 6377d791dcd1 |
children | 1009c33499e7 |
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 |
30283
d751e924cc29
patch 9.0.0477: missing dependency may cause crashes on incomplete build
Bram Moolenaar <Bram@vim.org>
parents:
29780
diff
changeset
|
23 // When not generating protos this is included in proto.h |
d751e924cc29
patch 9.0.0477: missing dependency may cause crashes on incomplete build
Bram Moolenaar <Bram@vim.org>
parents:
29780
diff
changeset
|
24 #ifdef PROTO |
d751e924cc29
patch 9.0.0477: missing dependency may cause crashes on incomplete build
Bram Moolenaar <Bram@vim.org>
parents:
29780
diff
changeset
|
25 # include "vim9.h" |
d751e924cc29
patch 9.0.0477: missing dependency may cause crashes on incomplete build
Bram Moolenaar <Bram@vim.org>
parents:
29780
diff
changeset
|
26 #endif |
d751e924cc29
patch 9.0.0477: missing dependency may cause crashes on incomplete build
Bram Moolenaar <Bram@vim.org>
parents:
29780
diff
changeset
|
27 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 * 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
|
30 * 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
|
31 */ |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
32 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
|
33 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
|
34 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 type_T *type; |
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 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
|
38 return NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 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
|
40 if (type != NULL) |
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 ((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
|
43 ++type_gap->ga_len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
48 /* |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
49 * Make a shallow copy of "type". |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
50 * When allocation fails returns "type". |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
51 */ |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
52 type_T * |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
53 copy_type(type_T *type, garray_T *type_gap) |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
54 { |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
55 type_T *copy = get_type_ptr(type_gap); |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
56 |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
57 if (copy == NULL) |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
58 return type; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
59 *copy = *type; |
31439
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
60 copy->tt_flags &= ~TTFLAG_STATIC; |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
61 |
30578
f1010a0e6226
patch 9.0.0624: leaking argument type array
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
62 if (type->tt_args != NULL |
f1010a0e6226
patch 9.0.0624: leaking argument type array
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
63 && func_type_add_arg_types(copy, type->tt_argcount, type_gap) == OK) |
f1010a0e6226
patch 9.0.0624: leaking argument type array
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
64 for (int i = 0; i < type->tt_argcount; ++i) |
f1010a0e6226
patch 9.0.0624: leaking argument type array
Bram Moolenaar <Bram@vim.org>
parents:
30576
diff
changeset
|
65 copy->tt_args[i] = type->tt_args[i]; |
30576
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
66 |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
67 return copy; |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
68 } |
72e6073a2822
patch 9.0.0623: error for modifying a const is not detected at compile time
Bram Moolenaar <Bram@vim.org>
parents:
30310
diff
changeset
|
69 |
31439
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
70 /* |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
71 * Inner part of copy_type_deep(). |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
72 * When allocation fails returns "type". |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
73 */ |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
74 static type_T * |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
75 copy_type_deep_rec(type_T *type, garray_T *type_gap, garray_T *seen_types) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
76 { |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
77 for (int i = 0; i < seen_types->ga_len; ++i) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
78 if (((type_T **)seen_types->ga_data)[i * 2] == type) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
79 // seen this type before, return the copy we made |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
80 return ((type_T **)seen_types->ga_data)[i * 2 + 1]; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
81 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
82 type_T *copy = copy_type(type, type_gap); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
83 if (ga_grow(seen_types, 1) == FAIL) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
84 return copy; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
85 ((type_T **)seen_types->ga_data)[seen_types->ga_len * 2] = type; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
86 ((type_T **)seen_types->ga_data)[seen_types->ga_len * 2 + 1] = copy; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
87 ++seen_types->ga_len; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
88 |
31740
22a4824d7964
patch 9.0.1202: crash when iterating over list of objects
Bram Moolenaar <Bram@vim.org>
parents:
31710
diff
changeset
|
89 if (copy->tt_member != NULL |
22a4824d7964
patch 9.0.1202: crash when iterating over list of objects
Bram Moolenaar <Bram@vim.org>
parents:
31710
diff
changeset
|
90 && copy->tt_type != VAR_OBJECT && copy->tt_type != VAR_CLASS) |
31439
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
91 copy->tt_member = copy_type_deep_rec(copy->tt_member, |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
92 type_gap, seen_types); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
93 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
94 if (type->tt_args != NULL) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
95 for (int i = 0; i < type->tt_argcount; ++i) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
96 copy->tt_args[i] = copy_type_deep_rec(copy->tt_args[i], |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
97 type_gap, seen_types); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
98 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
99 return copy; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
100 } |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
101 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
102 /* |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
103 * Make a deep copy of "type". |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
104 * When allocation fails returns "type". |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
105 */ |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
106 static type_T * |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
107 copy_type_deep(type_T *type, garray_T *type_gap) |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
108 { |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
109 garray_T seen_types; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
110 // stores type pairs : a type we have seen and the copy used |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
111 ga_init2(&seen_types, sizeof(type_T *) * 2, 20); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
112 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
113 type_T *res = copy_type_deep_rec(type, type_gap, &seen_types); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
114 |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
115 ga_clear(&seen_types); |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
116 return res; |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
117 } |
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
118 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 void |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 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
|
121 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 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
|
123 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
|
124 ga_clear(gap); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 |
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
|
127 /* |
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
|
128 * 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
|
129 * 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
|
130 */ |
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
|
131 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
|
132 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
|
133 { |
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
|
134 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
|
135 |
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
|
136 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
|
137 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
|
138 |
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
|
139 // 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
|
140 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
|
141 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
|
142 |
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
|
143 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
|
144 *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
|
145 |
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
|
146 if (ret->tt_member != NULL) |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
147 { |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
148 // tt_member points to the class_T for VAR_CLASS and VAR_OBJECT |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
149 if (type->tt_type != VAR_CLASS && type->tt_type != VAR_OBJECT) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
150 ret->tt_member = alloc_type(ret->tt_member); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
151 } |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
152 |
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
|
153 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
|
154 { |
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
|
155 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
|
156 |
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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 } |
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
|
162 |
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
|
163 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
|
164 } |
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
|
165 |
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
|
166 /* |
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
|
167 * 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
|
168 */ |
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
|
169 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
|
170 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
|
171 { |
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
|
172 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
|
173 |
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
|
174 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
|
175 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
|
176 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
|
177 { |
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
|
178 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
|
179 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
|
180 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
|
181 } |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
182 |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
183 // for an object and class tt_member is a pointer to the class |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
184 if (type->tt_type != VAR_OBJECT && type->tt_type != VAR_CLASS) |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
185 free_type(type->tt_member); |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
186 |
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
|
187 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
|
188 } |
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 |
27517
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
190 /* |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
191 * 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
|
192 */ |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
193 static int |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
194 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
|
195 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
196 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
|
197 && (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
|
198 || 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
|
199 && 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
|
200 && 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
|
201 && 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
|
202 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
203 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
204 /* |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
205 * 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
|
206 */ |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
207 void |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
208 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
|
209 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
210 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
|
211 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
212 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
|
213 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
214 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
|
215 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
224 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
|
225 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
226 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
|
227 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
228 --todo; |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
229 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
|
230 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
|
231 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
232 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
233 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
234 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
235 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
236 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
|
237 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
238 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
|
239 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
240 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
|
241 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 { |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
246 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
|
247 |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
248 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
|
249 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
|
250 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
251 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
252 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
253 } |
f00a7a2bee21
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()
Bram Moolenaar <Bram@vim.org>
parents:
27503
diff
changeset
|
254 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 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
|
257 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 // 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
|
261 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
|
262 return &t_list_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 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
|
264 || 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
|
265 return &t_list_empty; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 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
|
267 return &t_list_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 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
|
269 return &t_list_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 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
|
271 return &t_list_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 // 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
|
274 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
|
275 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 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
|
278 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
|
279 type->tt_argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 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
|
286 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 type_T *type; |
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 // 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
|
290 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
|
291 return &t_dict_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 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
|
293 || 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
|
294 return &t_dict_empty; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 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
|
296 return &t_dict_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 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
|
298 return &t_dict_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 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
|
300 return &t_dict_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 // 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
|
303 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
|
304 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 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
|
307 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
|
308 type->tt_argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
309 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
310 return type; |
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 * 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
|
315 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
316 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 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
|
318 { |
22284
6b385c2b9ff5
patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents:
22202
diff
changeset
|
319 type_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
|
320 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 if (type == NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 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
|
324 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
|
325 type->tt_argcount = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 type->tt_args = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 return type; |
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 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 * 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
|
332 * "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
|
333 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 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
|
336 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 // 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
|
338 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
|
339 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
340 // (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
|
341 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
|
342 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
343 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
|
344 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
345 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
|
346 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
|
347 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
348 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
|
349 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
350 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
|
351 { |
29008
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
352 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
|
353 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
|
354 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
355 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
|
356 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
357 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
|
358 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
359 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
|
360 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
|
361 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
362 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
|
363 } |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
364 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
|
365 { |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
366 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
|
367 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
|
368 else |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
369 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
|
370 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 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
|
373 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 * 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
|
377 * vararg). |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 int |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 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
|
381 type_T *functype, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 int argcount, |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 garray_T *type_gap) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 // 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
|
386 // pointer to type_gap. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 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
|
388 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 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
|
390 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
|
391 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 ((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
|
393 (void *)functype->tt_args; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 ++type_gap->ga_len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 return OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 /* |
30737
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
399 * Return TRUE if "type" is NULL, any or unknown. |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
400 * This also works for const (comparing with &t_any and &t_unknown doesn't). |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
401 */ |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
402 int |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
403 type_any_or_unknown(type_T *type) |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
404 { |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
405 return type == NULL || type->tt_type == VAR_ANY |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
406 || type->tt_type == VAR_UNKNOWN; |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
407 } |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
408 |
ec54b510e5ee
patch 9.0.0703: failing check for argument type for const any
Bram Moolenaar <Bram@vim.org>
parents:
30586
diff
changeset
|
409 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 * 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
|
411 * "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
|
412 * 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
|
413 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
414 * 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
|
415 * is "any". |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 */ |
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
|
417 static type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
418 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
|
419 { |
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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 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
|
426 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 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
|
428 return &t_bool; |
31443
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
429 if (tv->v_type == VAR_SPECIAL) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
430 { |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
431 if (tv->vval.v_number == VVAL_NULL) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
432 return &t_null; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
433 if (tv->vval.v_number == VVAL_NONE) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
434 return &t_none; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
435 if (tv->vval.v_number == VVAL_TRUE |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
436 || tv->vval.v_number == VVAL_TRUE) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
437 return &t_bool; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
438 return &t_unknown; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
439 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 { |
66b245d84f37
patch 8.2.4642: Vim9: in :def function script var cannot be null
Bram Moolenaar <Bram@vim.org>
parents:
28059
diff
changeset
|
444 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
|
445 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
|
446 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
|
447 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 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
|
450 { |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
451 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
|
452 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
|
453 |
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
|
454 // 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
|
455 // 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
|
456 // 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
|
457 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
|
458 && (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
|
459 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
|
460 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
|
461 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
|
462 // 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
|
463 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
464 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
|
465 || (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
|
466 || l->lv_type->tt_member != &t_any)) |
31435
8fe720031437
patch 9.0.1050: using freed memory when assigning to variable twice
Bram Moolenaar <Bram@vim.org>
parents:
31416
diff
changeset
|
467 // make a copy, lv_type may be freed if the list is freed |
31439
735de21c5ce7
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Bram Moolenaar <Bram@vim.org>
parents:
31435
diff
changeset
|
468 return copy_type_deep(l->lv_type, type_gap); |
22419
6a9e5c087c86
patch 8.2.1758: Vim9: type of unmaterialized list is wrong
Bram Moolenaar <Bram@vim.org>
parents:
22347
diff
changeset
|
469 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
|
470 return &t_list_number; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
471 if (l->lv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
472 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
473 return &t_list_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
474 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
|
475 |
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
|
476 // 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 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
|
487 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 dict_iterator_T iter; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 typval_T *value; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
490 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
|
491 |
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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 // 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
|
497 // more specific type. |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
498 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
|
499 || (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
|
500 || 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
|
501 return d->dv_type; |
24160
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
502 if (d->dv_copyID == copyID) |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
503 // avoid recursion |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
504 return &t_dict_any; |
e695db9a5465
patch 8.2.2621: typval2type() cannot handle recursive structures
Bram Moolenaar <Bram@vim.org>
parents:
24118
diff
changeset
|
505 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
|
506 |
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
|
507 // 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 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
|
518 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 char_u *name = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 ufunc_T *ufunc = NULL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 |
25692
17830c066d4b
patch 8.2.3382: crash when getting the type of a NULL partial
Bram Moolenaar <Bram@vim.org>
parents:
25646
diff
changeset
|
522 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
|
523 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 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
|
525 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
|
526 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 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
|
528 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 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
|
534 { |
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
|
535 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
|
536 |
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
|
537 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
|
538 { |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
539 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
|
540 |
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
|
541 internal_func_get_argcount(idx, &argcount, &min_argcount); |
31742
f578bef02249
patch 9.0.1203: return type of values() is always list<any>
Bram Moolenaar <Bram@vim.org>
parents:
31740
diff
changeset
|
542 member_type = internal_func_ret_type(idx, 0, NULL, &decl_type, |
f578bef02249
patch 9.0.1203: return type of values() is always list<any>
Bram Moolenaar <Bram@vim.org>
parents:
31740
diff
changeset
|
543 type_gap); |
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
|
544 } |
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
|
545 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
|
546 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
|
547 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 if (ufunc != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 // 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
|
551 // compiling the function. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 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
|
553 && 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
|
554 == FAIL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 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
|
559 { |
27010
b049c3b63a67
patch 8.2.4034: Coverity warns for possibly using a NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
26939
diff
changeset
|
560 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
|
561 && 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
|
562 { |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25135
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 *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
|
567 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
|
568 { |
26839
eb6d56ab4858
patch 8.2.3948: Vim9: failure with partial with unknown argument count
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
569 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
|
570 type->tt_min_argcount -= tv->vval.v_partial->pt_argc; |
30586
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
571 if (type->tt_argcount > 0 |
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
572 && func_type_add_arg_types(type, |
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
573 type->tt_argcount, type_gap) == OK) |
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
574 for (int i = 0; i < type->tt_argcount; ++i) |
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
575 type->tt_args[i] = |
4a1b0a12b430
patch 9.0.0628: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
30578
diff
changeset
|
576 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
|
577 i + tv->vval.v_partial->pt_argc]; |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
578 } |
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
|
579 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
|
580 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 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
|
582 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 |
31614
f3c7e573b7be
patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31612
diff
changeset
|
586 if (tv->v_type == VAR_CLASS) |
f3c7e573b7be
patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31612
diff
changeset
|
587 member_type = (type_T *)tv->vval.v_class; |
f3c7e573b7be
patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31612
diff
changeset
|
588 else if (tv->v_type == VAR_OBJECT && tv->vval.v_object != NULL) |
f3c7e573b7be
patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31612
diff
changeset
|
589 member_type = (type_T *)tv->vval.v_object->obj_class; |
f3c7e573b7be
patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents:
31612
diff
changeset
|
590 |
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
|
591 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
|
592 if (type == NULL) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 && 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
|
599 { |
b8a6a0007dc3
patch 8.2.3269: Vim9: wrong argument check for partial
Bram Moolenaar <Bram@vim.org>
parents:
25425
diff
changeset
|
600 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
|
601 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
|
602 } |
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
|
603 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
|
604 |
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
|
605 return type; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 /* |
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
|
609 * 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
|
610 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
611 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
|
612 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
|
613 { |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
614 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
|
615 && (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
|
616 && (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
|
617 } |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
618 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
619 /* |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
620 * 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
|
621 * "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
|
622 * 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
|
623 * "any". |
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
624 * 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
|
625 */ |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
626 type_T * |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
627 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
|
628 { |
26925
4e77f9961650
patch 8.2.3991: Vim9: error when extending dict<any>
Bram Moolenaar <Bram@vim.org>
parents:
26839
diff
changeset
|
629 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
|
630 |
31784
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
631 if (type != NULL) |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
632 { |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
633 if (type != &t_bool && (tv->v_type == VAR_NUMBER |
22494
4c21f7f6f9e3
patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents:
22492
diff
changeset
|
634 && (tv->vval.v_number == 0 || tv->vval.v_number == 1))) |
31784
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
635 // Number 0 and 1 and expression with "&&" or "||" can also be used |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
636 // for bool. |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
637 type = &t_number_bool; |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
638 else if (type != &t_float && tv->v_type == VAR_NUMBER) |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
639 // A number can also be used for float. |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
640 type = &t_number_float; |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
641 } |
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
|
642 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
|
643 } |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
644 |
7899b4e2880c
patch 8.2.1650: Vim9: result of && and || expression is not bool in script
Bram Moolenaar <Bram@vim.org>
parents:
22190
diff
changeset
|
645 /* |
31443
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
646 * Return TRUE if "type" can be used for a variable declaration. |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
647 * Give an error and return FALSE if not. |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
648 */ |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
649 int |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
650 valid_declaration_type(type_T *type) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
651 { |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
652 if (type->tt_type == VAR_SPECIAL // null, none |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
653 || type->tt_type == VAR_VOID) |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
654 { |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
655 char *tofree = NULL; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
656 char *name = type_name(type, &tofree); |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
657 semsg(_(e_invalid_type_for_object_member_str), name); |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
658 vim_free(tofree); |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
659 return FALSE; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
660 } |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
661 return TRUE; |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
662 } |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
663 |
9ae3720f9bd9
patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents:
31439
diff
changeset
|
664 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 * 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
|
666 * "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
|
667 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 type_T * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 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
|
670 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
678 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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 { |
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
|
685 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
|
686 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
687 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
|
688 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
|
689 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
|
690 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 * 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
|
694 * 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
|
695 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 int |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
697 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
|
698 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 garray_T type_list; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 type_T *actual_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 int res = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
703 if (expected == NULL) |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26680
diff
changeset
|
704 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
|
705 // |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
706 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
|
707 |
28002
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
708 // 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
|
709 // 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
|
710 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
|
711 || (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
|
712 && 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
|
713 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
|
714 else |
1012048eed26
patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
715 // 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
|
716 // 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
|
717 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
|
718 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
|
719 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
|
720 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
721 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
|
722 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
|
723 && 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
|
724 { |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
725 // 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
|
726 // "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
|
727 // 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
|
728 // incomplete type. |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
729 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
|
730 res = FAIL; |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
731 } |
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
732 } |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 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
|
734 return res; |
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 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 void |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
738 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
|
739 { |
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
|
740 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
|
741 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
742 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
|
743 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
|
744 } |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
745 |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
746 void |
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
747 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
|
748 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 |
23917
4b417b776b95
patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
753 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
|
754 { |
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
|
755 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
|
756 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
|
757 ? 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
|
758 : 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
|
759 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
|
760 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
|
761 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
|
762 ? 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
|
763 : 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
|
764 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
|
765 } |
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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 vim_free(tofree1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 vim_free(tofree2); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 * 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
|
778 * 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
|
779 * 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
|
780 * 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
|
781 * 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
|
782 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 { |
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
|
790 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
|
791 |
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
|
792 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
|
793 } |
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
|
794 |
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
|
795 /* |
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
|
796 * 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
|
797 * 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
|
798 */ |
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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 where_T where) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 int ret = OK; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 // 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
|
809 // 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
|
810 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
|
811 && !(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
|
812 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 { |
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
|
814 // 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
|
815 // 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
|
816 // 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
|
817 // 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
|
818 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
|
819 || 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
|
820 || 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
|
821 || (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
|
822 && 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
|
823 { |
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
|
824 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
|
825 && (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
|
826 // 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
|
827 return OK; |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31543
diff
changeset
|
828 if (expected->tt_type == VAR_FLOAT |
31784
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
829 && actual->tt_type == VAR_NUMBER |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
830 && ((expected->tt_flags & TTFLAG_NUMBER_OK) |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
831 || (actual->tt_flags & TTFLAG_FLOAT_OK))) |
6377d791dcd1
patch 9.0.1224: cannot call a :def function with a number for float argument
Bram Moolenaar <Bram@vim.org>
parents:
31750
diff
changeset
|
832 // Using a number where a float is expected is OK here. |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31543
diff
changeset
|
833 return OK; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 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
|
835 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
|
836 return FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 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
|
839 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 // "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
|
841 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
|
842 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
|
843 FALSE, where); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 } |
26680
1b288eb2fcdc
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
26678
diff
changeset
|
845 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
|
846 { |
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
|
847 // 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
|
848 // 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
|
849 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
|
850 { |
26678
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
851 if (actual->tt_member != NULL |
e16806237a70
patch 8.2.3868: Vim9: function test fails
Bram Moolenaar <Bram@vim.org>
parents:
26630
diff
changeset
|
852 && 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 } |
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
|
858 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
|
859 && 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
|
860 && (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
|
861 || (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
|
862 || 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
|
863 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
|
864 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
|
865 && 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
|
866 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 |
31551
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31543
diff
changeset
|
869 for (i = 0; i < expected->tt_argcount |
67d9fbe516a3
patch 9.0.1108: type error when using "any" type and adding to float
Bram Moolenaar <Bram@vim.org>
parents:
31543
diff
changeset
|
870 && i < actual->tt_argcount; ++i) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 // 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
|
872 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
|
873 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
|
874 where) == FAIL) |
21711
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 ret = FAIL; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 break; |
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 } |
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
|
880 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
|
881 && 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
|
882 // 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
|
883 ret = MAYBE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 } |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
885 else if (expected->tt_type == VAR_OBJECT) |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
886 { |
31750
13cecb002fe6
patch 9.0.1207: error when object type is expected but getting "any"
Bram Moolenaar <Bram@vim.org>
parents:
31742
diff
changeset
|
887 if (actual->tt_type == VAR_ANY) |
13cecb002fe6
patch 9.0.1207: error when object type is expected but getting "any"
Bram Moolenaar <Bram@vim.org>
parents:
31742
diff
changeset
|
888 return MAYBE; // use runtime type check |
13cecb002fe6
patch 9.0.1207: error when object type is expected but getting "any"
Bram Moolenaar <Bram@vim.org>
parents:
31742
diff
changeset
|
889 if (actual->tt_type != VAR_OBJECT) |
13cecb002fe6
patch 9.0.1207: error when object type is expected but getting "any"
Bram Moolenaar <Bram@vim.org>
parents:
31742
diff
changeset
|
890 return FAIL; // don't use tt_member |
13cecb002fe6
patch 9.0.1207: error when object type is expected but getting "any"
Bram Moolenaar <Bram@vim.org>
parents:
31742
diff
changeset
|
891 |
31704
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
892 // check the class, base class or an implemented interface matches |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
893 class_T *cl; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
894 for (cl = (class_T *)actual->tt_member; cl != NULL; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
895 cl = cl->class_extends) |
31704
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
896 { |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
897 if ((class_T *)expected->tt_member == cl) |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
898 break; |
31704
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
899 int i; |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
900 for (i = cl->class_interface_count - 1; i >= 0; --i) |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
901 if ((class_T *)expected->tt_member |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
902 == cl->class_interfaces_cl[i]) |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
903 break; |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
904 if (i >= 0) |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
905 break; |
69ee530cac28
patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents:
31698
diff
changeset
|
906 } |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
907 if (cl == NULL) |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
908 ret = FAIL; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
909 } |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
910 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 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
|
912 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
|
913 } |
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
|
914 |
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
|
915 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
|
916 && 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
|
917 && (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
|
918 // 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
|
919 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
|
920 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 return ret; |
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 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 /* |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
925 * 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
|
926 * "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
|
927 * 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
|
928 */ |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 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
|
936 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
937 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
|
938 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
|
939 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
|
940 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
941 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
|
942 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
|
943 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
|
944 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
945 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
|
946 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
|
947 } |
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
|
948 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
|
949 { |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28231
diff
changeset
|
950 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
|
951 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
|
952 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
953 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
|
954 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
|
955 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
956 |
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
|
957 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
|
958 { |
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
|
959 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
|
960 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
|
961 |
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
|
962 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
|
963 { |
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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 } |
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
|
969 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
|
970 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
|
971 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
|
972 { |
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
973 expected = type->tt_args[type->tt_argcount - 1]; |
31612
c467d6e70972
patch 9.0.1138: crash when expecting varargs but it is something else
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
974 if (expected != NULL && expected->tt_type == VAR_LIST) |
28952
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
975 expected = expected->tt_member; |
31612
c467d6e70972
patch 9.0.1138: crash when expecting varargs but it is something else
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
976 if (expected == NULL) |
c467d6e70972
patch 9.0.1138: crash when expecting varargs but it is something else
Bram Moolenaar <Bram@vim.org>
parents:
31551
diff
changeset
|
977 expected = &t_any; |
28952
ba083decce5d
patch 8.2.4998: Vim9: crash when using multiple funcref()
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
978 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
979 else |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
980 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
|
981 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
|
982 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
|
983 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
984 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
|
985 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
986 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23481
diff
changeset
|
987 /* |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 * 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
|
989 * 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
|
990 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 char_u * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 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
|
993 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 char_u *p = start; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 if (optional && *p == '?') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 ++p; |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
998 |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
999 // Also skip over "." for imported classes: "import.ClassName". |
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
1000 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '.') |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 // 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
|
1004 if (*skipwhite(p) == '<') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 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
|
1008 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 if (*p == '>') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 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
|
1013 && 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
|
1014 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 if (*p == '(') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 // handle func(args): type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 while (*p != ')' && *p != NUL) |
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 char_u *sp = p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 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
|
1024 p += 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 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
|
1026 if (p == sp) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 return p; // syntax error |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 if (*p == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 p = skipwhite(p + 1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 if (*p == ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 if (p[1] == ':') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 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
|
1035 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 // handle func: return_type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 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
|
1043 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 return p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 } |
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 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 * 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
|
1051 * 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
|
1052 * "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
|
1053 * 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
|
1054 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 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
|
1056 parse_type_member( |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1057 char_u **arg, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1058 type_T *type, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1059 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
|
1060 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
|
1061 char *info) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 { |
29780
9f8dd1b77563
patch 9.0.0229: Vim9: error message for missing type is not clear
Bram Moolenaar <Bram@vim.org>
parents:
29008
diff
changeset
|
1063 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
|
1064 type_T *member_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 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
|
1066 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 if (**arg != '<') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1069 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1070 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1071 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
|
1072 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
|
1073 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
|
1074 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
|
1075 } |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1076 return NULL; |
21711
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 *arg = skipwhite(*arg + 1); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1080 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
|
1081 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
|
1082 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 *arg = skipwhite(*arg); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 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
|
1086 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1087 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
|
1088 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
|
1089 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 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
|
1094 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
|
1095 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
|
1096 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 * 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
|
1100 * 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
|
1101 * 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
|
1102 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 type_T * |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1104 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
|
1105 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 char_u *p = *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 size_t len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
1109 // Skip over the first word. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 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
|
1111 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 len = p - *arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 switch (**arg) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 case 'a': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 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
|
1118 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 return &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 case 'b': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1124 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
|
1125 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 return &t_bool; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 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
|
1130 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 return &t_blob; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 case 'c': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1136 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
|
1137 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1139 return &t_channel; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1142 case 'd': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1143 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
|
1144 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1146 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
|
1147 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
|
1148 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 case 'f': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 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
|
1152 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 return &t_float; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 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
|
1157 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 type_T *type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 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
|
1160 int argcount = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 int flags = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 int first_optional = -1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 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
|
1164 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 // func({type}, ...{type}): {type} |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 if (**arg == '(') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 // "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
|
1170 // not return a value. |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 ret_type = &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 p = ++*arg; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 argcount = 0; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 while (*p != NUL && *p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 if (*p == '?') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 if (first_optional == -1) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 first_optional = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 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
|
1184 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 flags |= TTFLAG_VARARGS; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 p += 3; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 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
|
1189 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1190 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1191 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
|
1192 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1195 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
|
1196 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1197 return NULL; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1198 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
|
1199 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 // Nothing comes after "...{type}". |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 if (flags & TTFLAG_VARARGS) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 if (*p != ',' && *skipwhite(p) == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1206 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
|
1207 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
|
1208 ",", p); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1209 return NULL; |
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 if (*p == ',') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 ++p; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 if (!VIM_ISWHITE(*p)) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1216 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
|
1217 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
|
1218 ",", p - 1); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1219 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1220 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1222 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1223 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
|
1224 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1225 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1226 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
|
1227 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 p = skipwhite(p); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1232 if (*p != ')') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1234 if (give_error) |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25788
diff
changeset
|
1235 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
|
1236 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 *arg = p + 1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 if (**arg == ':') |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 // parse return type |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 ++*arg; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1244 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
|
1245 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
|
1246 ":", *arg - 1); |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 *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
|
1248 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
|
1249 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
|
1250 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1252 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
|
1253 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
|
1254 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1256 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
|
1257 type->tt_flags = flags; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 if (argcount > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1260 type->tt_argcount = argcount; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1261 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
|
1262 ? argcount : first_optional; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 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
|
1264 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
|
1265 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 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
|
1267 sizeof(type_T *) * argcount); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 return type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 case 'j': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1274 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
|
1275 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1276 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 return &t_job; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 case 'l': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 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
|
1282 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 *arg += len; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1284 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
|
1285 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
|
1286 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 case 'n': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 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
|
1290 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 return &t_number; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 case 's': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 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
|
1297 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 return &t_string; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1300 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1301 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 case 'v': |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 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
|
1304 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1305 *arg += len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1306 return &t_void; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
1311 // It can be a class or interface name, possibly imported. |
31645
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1312 typval_T tv; |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1313 tv.v_type = VAR_UNKNOWN; |
31706
824fc05d9571
patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents:
31704
diff
changeset
|
1314 if (eval_variable_import(*arg, &tv) == OK) |
31645
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1315 { |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1316 if (tv.v_type == VAR_CLASS && tv.vval.v_class != NULL) |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1317 { |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1318 type_T *type = get_type_ptr(type_gap); |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1319 if (type != NULL) |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1320 { |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1321 // Although the name is that of a class or interface, the type |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1322 // uses will be an object. |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1323 type->tt_type = VAR_OBJECT; |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1324 type->tt_member = (type_T *)tv.vval.v_class; |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1325 clear_tv(&tv); |
31710
50241d494268
patch 9.0.1187: test for using imported class fails
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
1326 |
31645
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1327 *arg += len; |
31710
50241d494268
patch 9.0.1187: test for using imported class fails
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
1328 // Skip over ".ClassName". |
50241d494268
patch 9.0.1187: test for using imported class fails
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
1329 while (ASCII_ISALNUM(**arg) || **arg == '_' || **arg == '.') |
50241d494268
patch 9.0.1187: test for using imported class fails
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
1330 ++*arg; |
50241d494268
patch 9.0.1187: test for using imported class fails
Bram Moolenaar <Bram@vim.org>
parents:
31706
diff
changeset
|
1331 |
31645
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1332 return type; |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1333 } |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1334 } |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1335 |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1336 clear_tv(&tv); |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1337 } |
fc259e8db5bf
patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents:
31614
diff
changeset
|
1338 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1339 if (give_error) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1340 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
|
1341 return NULL; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 * 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
|
1346 * "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
|
1347 * 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
|
1348 */ |
23362
f181fe2150ab
patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents:
23338
diff
changeset
|
1349 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
|
1350 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
|
1351 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 |
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
|
1354 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
|
1355 return FALSE; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 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
|
1357 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 switch (type1->tt_type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 case VAR_UNKNOWN: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 case VAR_ANY: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 case VAR_VOID: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 case VAR_SPECIAL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 case VAR_BOOL: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 case VAR_NUMBER: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 case VAR_FLOAT: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 case VAR_STRING: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 case VAR_BLOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 case VAR_JOB: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 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
|
1371 case VAR_INSTR: |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
1372 case VAR_CLASS: |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
1373 case VAR_OBJECT: |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 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
|
1375 case VAR_LIST: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 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
|
1377 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
|
1378 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 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
|
1380 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
|
1381 || 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
|
1382 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 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
|
1384 || 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
|
1385 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 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
|
1387 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
|
1388 && !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
|
1389 flags)) |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 return FALSE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 return TRUE; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 * 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
|
1398 * "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
|
1399 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 void |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 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
|
1402 { |
25425
effe5f2b4d01
patch 8.2.3249: Vim9: error for re-imported function with default argument
Bram Moolenaar <Bram@vim.org>
parents:
25326
diff
changeset
|
1403 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
|
1404 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 *dest = type1; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 |
22322
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1409 // 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
|
1410 // 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
|
1411 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
|
1412 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1413 *dest = type2; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1414 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1415 } |
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
|
1416 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
|
1417 { |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1418 *dest = type1; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1419 return; |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1420 } |
a5b16c9eee9d
patch 8.2.1710: Vim9: list of list type can be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22284
diff
changeset
|
1421 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 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
|
1423 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 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
|
1425 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 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
|
1429 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
|
1430 *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
|
1431 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 *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
|
1433 return; |
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 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
|
1436 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 type_T *common; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 |
28059
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1439 // 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
|
1440 // 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
|
1441 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
|
1442 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1443 *dest = type2; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1444 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1445 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1446 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
|
1447 { |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1448 *dest = type1; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1449 return; |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1450 } |
230115610b6a
patch 8.2.4554: Vim9: using null values not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
1451 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 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
|
1453 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
|
1454 && type1->tt_argcount >= 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 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
|
1457 int i; |
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 *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
|
1460 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
|
1461 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 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
|
1463 type_gap) == OK) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 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
|
1465 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
|
1466 &(*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
|
1467 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 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
|
1470 // 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
|
1471 // arguments. |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 *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
|
1473 |
22492
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1474 // Use the minimum of min_argcount. |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1475 (*dest)->tt_min_argcount = |
0e03ef68e738
patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents:
22419
diff
changeset
|
1476 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
|
1477 ? 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
|
1478 return; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 } |
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 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 *dest = &t_any; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 |
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
|
1485 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1486 * 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
|
1487 * 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
|
1488 * 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
|
1489 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1490 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1491 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
|
1492 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1493 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
|
1494 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1495 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1496 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1497 * 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
|
1498 * 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
|
1499 * 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
|
1500 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1501 int |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1502 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
|
1503 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1504 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
|
1505 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
|
1506 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1507 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
|
1508 return FAIL; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1509 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
|
1510 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
|
1511 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
|
1512 ++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
|
1513 return OK; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1514 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1515 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1516 /* |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1517 * 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
|
1518 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1519 void |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1520 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
|
1521 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1522 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
|
1523 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
|
1524 + 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
|
1525 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1526 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
|
1527 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
|
1528 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1529 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1530 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1531 * 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
|
1532 * 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
|
1533 * 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
|
1534 * 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
|
1535 */ |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1536 type_T * |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1537 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
|
1538 { |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1539 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
|
1540 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1541 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
|
1542 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
|
1543 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
|
1544 ->type_curr; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1545 } |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1546 |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1547 /* |
27503
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1548 * 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
|
1549 * 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
|
1550 * 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
|
1551 * 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
|
1552 */ |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1553 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
|
1554 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
|
1555 { |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1556 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
|
1557 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1558 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
|
1559 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
|
1560 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
|
1561 ->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
|
1562 } |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1563 |
4cea92e99a5a
patch 8.2.4279: Vim9: cannot change item type with map() after range()
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
1564 /* |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1565 * 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
|
1566 * 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
|
1567 * 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
|
1568 * 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
|
1569 * 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
|
1570 */ |
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
|
1571 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
|
1572 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
|
1573 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
|
1574 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
|
1575 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
|
1576 { |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1577 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
|
1578 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
|
1579 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
|
1580 int i; |
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1581 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
|
1582 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
|
1583 |
26935
ccb9be1cdd71
patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents:
26925
diff
changeset
|
1584 // 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
|
1585 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
|
1586 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
|
1587 |
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
|
1588 // 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
|
1589 // 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
|
1590 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
|
1591 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
|
1592 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
|
1593 { |
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
|
1594 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
|
1595 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
|
1596 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
|
1597 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
|
1598 } |
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
|
1599 |
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
|
1600 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
|
1601 } |
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
|
1602 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 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
|
1605 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 switch (type) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 case VAR_UNKNOWN: break; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 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
|
1610 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
|
1611 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
|
1612 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
|
1613 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
|
1614 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
|
1615 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
|
1616 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
|
1617 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
|
1618 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
|
1619 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
|
1620 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
|
1621 case VAR_INSTR: return "instr"; |
31396
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
1622 case VAR_CLASS: return "class"; |
307f68a41b03
patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
30737
diff
changeset
|
1623 case VAR_OBJECT: return "object"; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 case VAR_FUNC: |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 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
|
1627 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 return "unknown"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 /* |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 * 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
|
1633 * 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
|
1634 */ |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 char * |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 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
|
1637 { |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1638 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
|
1639 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
|
1640 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 *tofree = NULL; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1642 if (type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1643 return "[unknown]"; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
22898
diff
changeset
|
1644 name = vartype_name(type->tt_type); |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1645 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 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
|
1647 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 char *member_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 char *member_name = type_name(type->tt_member, &member_free); |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1650 size_t len = STRLEN(name) + STRLEN(member_name) + 3; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 *tofree = alloc(len); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 if (*tofree != NULL) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 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
|
1655 vim_free(member_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 return *tofree; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 } |
31698
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1659 |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1660 if (type->tt_type == VAR_OBJECT || type->tt_type == VAR_CLASS) |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1661 { |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1662 char_u *class_name = ((class_T *)type->tt_member)->class_name; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1663 size_t len = STRLEN(name) + STRLEN(class_name) + 3; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1664 *tofree = alloc(len); |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1665 if (*tofree != NULL) |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1666 { |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1667 vim_snprintf(*tofree, len, "%s<%s>", name, class_name); |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1668 return *tofree; |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1669 } |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1670 } |
9fba3e8bbadc
patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
31661
diff
changeset
|
1671 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 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
|
1673 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 garray_T ga; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 int i; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 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
|
1677 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 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
|
1679 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
|
1680 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 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
|
1682 ga.ga_len += 5; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 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
|
1685 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 char *arg_type; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 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
|
1690 arg_type = "[unknown]"; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 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
|
1693 if (i > 0) |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 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
|
1696 ga.ga_len += 2; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 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
|
1699 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
|
1700 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 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
|
1702 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
|
1703 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
|
1704 *((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
|
1705 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
|
1706 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
|
1707 } |
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
|
1708 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
|
1709 // 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
|
1710 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
|
1711 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 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
|
1713 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
|
1714 else |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 { |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 char *ret_free; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 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
|
1718 int len; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 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
|
1721 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
|
1722 goto failed; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 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
|
1724 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
|
1725 vim_free(ret_free); |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 } |
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
|
1727 *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
|
1728 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
|
1729 |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1730 failed: |
49d8b54802f3
patch 8.2.5026: Vim9: a few lines not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
28952
diff
changeset
|
1731 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
|
1732 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
|
1733 return "[unknown]"; |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 return name; |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 } |
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 |
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
|
1739 /* |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1740 * "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
|
1741 */ |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1742 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
|
1743 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
|
1744 { |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1745 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
|
1746 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
|
1747 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
|
1748 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
|
1749 |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1750 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
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 } |
d3e064f54890
patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents:
23527
diff
changeset
|
1760 |
21711
d2dee69de7c7
patch 8.2.1405: Vim9: vim9compile.c is getting too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 #endif // FEAT_EVAL |