@@ -906,55 +906,48 @@ pub(crate) fn resolve_method_name(
906
906
let type_engine = ctx. engines . te ( ) ;
907
907
let engines = ctx. engines ( ) ;
908
908
909
- // retrieve the function declaration using the components of the method name
910
- let ( decl_ref, type_id) = match & method_name_binding. inner {
909
+ // Helper: first argument type or an unknown placeholder.
910
+ let first_arg_or_unknown = || {
911
+ arguments_types
912
+ . first ( )
913
+ . cloned ( )
914
+ . unwrap_or_else ( || type_engine. new_unknown ( ) )
915
+ } ;
916
+
917
+ let ( type_id, module_path, method_ident) = match & method_name_binding. inner {
911
918
MethodName :: FromType {
912
919
call_path_binding,
913
920
method_name,
914
921
} => {
915
- // type check the call path
916
922
let type_id = call_path_binding
917
923
. type_check_with_type_info ( handler, & mut ctx)
918
924
. unwrap_or_else ( |err| type_engine. id_of_error_recovery ( err) ) ;
919
925
920
- // find the module that the symbol is in
921
- let type_info_prefix = & call_path_binding
926
+ let type_info_path = call_path_binding
922
927
. inner
923
- . to_fullpath ( engines, ctx. namespace ( ) )
924
- . prefixes ;
928
+ . to_fullpath ( engines, ctx. namespace ( ) ) ;
929
+ let module_path = type_info_path . prefixes . clone ( ) ;
925
930
ctx. namespace ( )
926
- . require_module_from_absolute_path ( handler, type_info_prefix ) ?;
931
+ . require_module_from_absolute_path ( handler, & module_path ) ?;
927
932
928
- // find the method
929
- let decl_ref = ctx. find_method_for_type (
930
- handler,
931
- type_id,
932
- type_info_prefix,
933
- method_name,
934
- ctx. type_annotation ( ) ,
935
- arguments_types,
936
- Some ( & method_name_binding. inner ) ,
937
- ) ?;
938
-
939
- ( decl_ref, type_id)
933
+ ( type_id, module_path, method_name)
940
934
}
935
+
941
936
MethodName :: FromTrait { call_path } => {
942
- // find the module that the symbol is in
943
- let module_path = match call_path. callpath_type {
937
+ let module_path: Vec < _ > = match call_path. callpath_type {
944
938
CallPathType :: RelativeToPackageRoot => {
945
939
let mut path = vec ! [ ctx. namespace( ) . current_package_name( ) . clone( ) ] ;
946
- for ident in call_path. prefixes . iter ( ) {
947
- path. push ( ident. clone ( ) )
948
- }
940
+ path. extend ( call_path. prefixes . iter ( ) . cloned ( ) ) ;
949
941
path
950
942
}
951
943
CallPathType :: Full => call_path. prefixes . clone ( ) ,
952
944
CallPathType :: Ambiguous => {
945
+ let first = call_path. prefixes . first ( ) . expect ( "prefixes is non-empty" ) ;
953
946
if ctx
954
947
. namespace ( )
955
948
. current_module ( )
956
949
. submodules ( )
957
- . contains_key ( call_path . prefixes . first ( ) . unwrap ( ) . as_str ( ) )
950
+ . contains_key ( first. as_str ( ) )
958
951
{
959
952
ctx. namespace ( ) . prepend_module_path ( & call_path. prefixes )
960
953
} else {
@@ -963,72 +956,35 @@ pub(crate) fn resolve_method_name(
963
956
}
964
957
} ;
965
958
966
- // find the type of the first argument
967
- let type_id = arguments_types
968
- . first ( )
969
- . cloned ( )
970
- . unwrap_or_else ( || type_engine. new_unknown ( ) ) ;
971
-
972
- // find the method
973
- let decl_ref = ctx. find_method_for_type (
974
- handler,
975
- type_id,
976
- & module_path,
977
- & call_path. suffix ,
978
- ctx. type_annotation ( ) ,
979
- arguments_types,
980
- Some ( & method_name_binding. inner ) ,
981
- ) ?;
982
-
983
- ( decl_ref, type_id)
959
+ let type_id = first_arg_or_unknown ( ) ;
960
+ ( type_id, module_path, & call_path. suffix )
984
961
}
985
- MethodName :: FromModule { method_name } => {
986
- // find the module that the symbol is in
987
- let module_path = ctx. namespace ( ) . current_mod_path ( ) ;
988
962
989
- // find the type of the first argument
990
- let type_id = arguments_types
991
- . first ( )
992
- . cloned ( )
993
- . unwrap_or_else ( || type_engine. new_unknown ( ) ) ;
994
-
995
- // find the method
996
- let decl_ref = ctx. find_method_for_type (
997
- handler,
998
- type_id,
999
- module_path. as_slice ( ) ,
1000
- method_name,
1001
- ctx. type_annotation ( ) ,
1002
- arguments_types,
1003
- Some ( & method_name_binding. inner ) ,
1004
- ) ?;
1005
-
1006
- ( decl_ref, type_id)
963
+ MethodName :: FromModule { method_name } => {
964
+ let module_path = ctx. namespace ( ) . current_mod_path ( ) . to_vec ( ) ;
965
+ let type_id = first_arg_or_unknown ( ) ;
966
+ ( type_id, module_path, method_name)
1007
967
}
968
+
1008
969
MethodName :: FromQualifiedPathRoot {
1009
970
ty, method_name, ..
1010
971
} => {
1011
- // type check the call path
1012
972
let type_id = ty. type_id ( ) ;
1013
-
1014
- // find the module that the symbol is in
1015
- let module_path = ctx. namespace ( ) . current_mod_path ( ) ;
1016
-
1017
- // find the method
1018
- let decl_ref = ctx. find_method_for_type (
1019
- handler,
1020
- type_id,
1021
- module_path,
1022
- method_name,
1023
- ctx. type_annotation ( ) ,
1024
- arguments_types,
1025
- Some ( & method_name_binding. inner ) ,
1026
- ) ?;
1027
-
1028
- ( decl_ref, type_id)
973
+ let module_path = ctx. namespace ( ) . current_mod_path ( ) . to_vec ( ) ;
974
+ ( type_id, module_path, method_name)
1029
975
}
1030
976
} ;
1031
977
978
+ let decl_ref = ctx. find_method_for_type (
979
+ handler,
980
+ type_id,
981
+ module_path. as_slice ( ) ,
982
+ method_ident,
983
+ ctx. type_annotation ( ) ,
984
+ arguments_types,
985
+ Some ( & method_name_binding. inner ) ,
986
+ ) ?;
987
+
1032
988
ctx. engines . obs ( ) . raise_on_after_method_resolution (
1033
989
& ctx,
1034
990
method_name_binding,
0 commit comments