11use std:: sync:: Arc ;
22
33use emmylua_parser:: { LuaAstNode , LuaCallExpr , LuaExpr , LuaIndexExpr , LuaSyntaxKind } ;
4- use hashbrown:: HashSet ;
54use rowan:: TextRange ;
65
76use super :: {
87 super :: { InferGuard , LuaInferCache , instantiate_type_generic, resolve_signature} ,
98 InferFailReason , InferResult ,
109} ;
11- use crate :: semantic:: overload_resolve:: callable_accepts_args;
1210use crate :: {
1311 AsyncState , CacheEntry , DbIndex , InFiled , LuaFunctionType , LuaGenericType , LuaInstanceType ,
1412 LuaIntersectionType , LuaOperatorMetaMethod , LuaOperatorOwner , LuaSemanticDeclId , LuaSignature ,
@@ -18,9 +16,11 @@ use crate::{
1816use crate :: {
1917 InferGuardRef ,
2018 semantic:: {
21- generic:: TypeSubstitutor , infer:: narrow:: get_type_at_call_expr_inline_cast,
22- infer_node_semantic_decl, member:: find_member_origin_owner,
23- overload_resolve:: collect_callable_overload_groups,
19+ generic:: TypeSubstitutor ,
20+ infer:: narrow:: get_type_at_call_expr_inline_cast,
21+ infer_node_semantic_decl,
22+ member:: find_member_origin_owner,
23+ overload_resolve:: { collect_callable_overload_groups, match_callable_by_arg_types} ,
2424 } ,
2525} ;
2626use crate :: { build_self_type, infer_call_generic, infer_self_type, semantic:: infer_expr} ;
@@ -236,13 +236,12 @@ fn infer_doc_function(
236236 Ok ( func. clone ( ) . into ( ) )
237237}
238238
239- fn filter_callable_overloads_by_call_args (
239+ fn filter_callable_overloads_by_args (
240240 db : & DbIndex ,
241241 cache : & mut LuaInferCache ,
242242 overloads : Vec < Arc < LuaFunctionType > > ,
243243 call_expr : & LuaCallExpr ,
244244 args_count : Option < usize > ,
245- strict_arg_filter : bool ,
246245) -> Result < Vec < Arc < LuaFunctionType > > , InferFailReason > {
247246 let args = call_expr. get_args_list ( ) . ok_or ( InferFailReason :: None ) ?;
248247 let expr_types = super :: infer_expr_list_types (
@@ -255,35 +254,11 @@ fn filter_callable_overloads_by_call_args(
255254 . into_iter ( )
256255 . map ( |( ty, _) | ty)
257256 . collect :: < Vec < _ > > ( ) ;
258- let is_colon_call = call_expr. is_colon_call ( ) ;
259257
260258 Ok ( overloads
261259 . into_iter ( )
262- . filter ( |func| {
263- let callable_tpls = func
264- . get_generic_params ( )
265- . iter ( )
266- . map ( |generic_tpl| generic_tpl. get_tpl_id ( ) )
267- . collect :: < HashSet < _ > > ( ) ;
268-
269- if callable_tpls. is_empty ( ) && !strict_arg_filter {
270- return true ;
271- }
272-
273- let has_tpls = !callable_tpls. is_empty ( ) ;
274- let mut substitutor = TypeSubstitutor :: new ( ) ;
275- substitutor. add_need_infer_tpls ( callable_tpls) ;
276- let match_func = if has_tpls {
277- let func_type = LuaType :: DocFunction ( func. clone ( ) ) ;
278- match instantiate_type_generic ( db, & func_type, & substitutor) {
279- LuaType :: DocFunction ( doc_func) => doc_func,
280- _ => func. clone ( ) ,
281- }
282- } else {
283- func. clone ( )
284- } ;
285-
286- callable_accepts_args ( db, & match_func, & expr_types, is_colon_call, args_count)
260+ . filter_map ( |func| {
261+ match_callable_by_arg_types ( db, cache, func, & expr_types, call_expr, args_count, true )
287262 } )
288263 . collect ( ) )
289264}
@@ -542,13 +517,12 @@ fn infer_union(
542517 let mut overload_groups = Vec :: new ( ) ;
543518 collect_callable_overload_groups ( db, & ty, & mut overload_groups) ?;
544519 for overloads in overload_groups {
545- let compatible_overloads = filter_callable_overloads_by_call_args (
520+ let compatible_overloads = filter_callable_overloads_by_args (
546521 db,
547522 cache,
548523 overloads. clone ( ) ,
549524 & call_expr,
550525 args_count,
551- true ,
552526 ) ?;
553527 if compatible_overloads. is_empty ( ) {
554528 fallback_overloads. extend ( overloads) ;
@@ -586,14 +560,6 @@ fn infer_union(
586560 let Some ( first_func) = first_func else {
587561 if !fallback_overloads. is_empty ( ) {
588562 let contains_tpl = fallback_overloads. iter ( ) . any ( |func| func. contain_tpl ( ) ) ;
589- let fallback_overloads = filter_callable_overloads_by_call_args (
590- db,
591- cache,
592- fallback_overloads,
593- & call_expr,
594- args_count,
595- false ,
596- ) ?;
597563 return resolve_signature (
598564 db,
599565 cache,
0 commit comments