1
- use std:: sync:: Arc ;
1
+ use std:: { ops :: Deref , sync:: Arc } ;
2
2
3
- use emmylua_parser:: LuaCallExpr ;
3
+ use emmylua_parser:: { LuaCallExpr , LuaExpr } ;
4
4
5
- use crate :: db_index:: { DbIndex , LuaFunctionType , LuaType } ;
5
+ use crate :: {
6
+ VariadicType ,
7
+ db_index:: { DbIndex , LuaFunctionType , LuaType } ,
8
+ infer_expr,
9
+ } ;
6
10
7
11
use super :: {
8
12
LuaInferCache ,
9
13
generic:: instantiate_func_generic,
10
14
infer:: { InferCallFuncResult , InferFailReason } ,
11
- infer_expr,
12
15
type_check:: check_type_compact,
13
16
} ;
14
17
@@ -21,10 +24,12 @@ pub fn resolve_signature(
21
24
arg_count : Option < usize > ,
22
25
) -> InferCallFuncResult {
23
26
let args = call_expr. get_args_list ( ) . ok_or ( InferFailReason :: None ) ?;
24
- let mut expr_types = Vec :: new ( ) ;
25
- for arg in args. get_args ( ) {
26
- expr_types. push ( infer_expr ( db, cache, arg) ?) ;
27
- }
27
+ let expr_types = infer_expr_list_types (
28
+ db,
29
+ cache,
30
+ args. get_args ( ) . collect :: < Vec < _ > > ( ) . as_slice ( ) ,
31
+ arg_count,
32
+ ) ;
28
33
if is_generic {
29
34
resolve_signature_by_generic ( db, cache, overloads, call_expr, expr_types, arg_count)
30
35
} else {
@@ -139,3 +144,46 @@ fn resolve_signature_by_args(
139
144
. or_else ( || overloads. last ( ) . cloned ( ) )
140
145
. ok_or ( InferFailReason :: None )
141
146
}
147
+
148
+ fn infer_expr_list_types (
149
+ db : & DbIndex ,
150
+ cache : & mut LuaInferCache ,
151
+ exprs : & [ LuaExpr ] ,
152
+ var_count : Option < usize > ,
153
+ ) -> Vec < LuaType > {
154
+ let mut value_types = Vec :: new ( ) ;
155
+ for ( idx, expr) in exprs. iter ( ) . enumerate ( ) {
156
+ let expr_type = infer_expr ( db, cache, expr. clone ( ) ) . unwrap_or ( LuaType :: Unknown ) ;
157
+ match expr_type {
158
+ LuaType :: Variadic ( variadic) => {
159
+ if let Some ( var_count) = var_count {
160
+ if idx < var_count {
161
+ for i in idx..var_count {
162
+ if let Some ( typ) = variadic. get_type ( i - idx) {
163
+ value_types. push ( typ. clone ( ) ) ;
164
+ } else {
165
+ break ;
166
+ }
167
+ }
168
+ }
169
+ } else {
170
+ match variadic. deref ( ) {
171
+ VariadicType :: Base ( base) => {
172
+ value_types. push ( base. clone ( ) ) ;
173
+ }
174
+ VariadicType :: Multi ( vecs) => {
175
+ for typ in vecs {
176
+ value_types. push ( typ. clone ( ) ) ;
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ break ;
183
+ }
184
+ _ => value_types. push ( expr_type. clone ( ) ) ,
185
+ }
186
+ }
187
+
188
+ value_types
189
+ }
0 commit comments