@@ -7,7 +7,7 @@ use crate::{
7
7
engine_threading:: * ,
8
8
language:: {
9
9
parsed:: { MethodName , TreeType } ,
10
- ty:: { self , TyDecl , TyExpression } ,
10
+ ty:: { self , TyDecl , TyExpression , TyFunctionDisplay } ,
11
11
CallPath , QualifiedCallPath , Visibility ,
12
12
} ,
13
13
monomorphization:: { monomorphize_with_modpath, MonomorphizeHelper } ,
@@ -23,6 +23,7 @@ use crate::{
23
23
EnforceTypeArguments , SubstTypesContext , TraitConstraint , TypeParameter , TypeSubstMap ,
24
24
UnifyCheck ,
25
25
} ;
26
+ use itertools:: Itertools ;
26
27
use sway_error:: {
27
28
error:: CompileError ,
28
29
handler:: { ErrorEmitted , Handler } ,
@@ -915,10 +916,10 @@ impl<'a> TypeCheckContext<'a> {
915
916
// While collecting unifications we don't decay numeric and will ignore this error.
916
917
if self . collecting_unifications {
917
918
return Err ( handler. emit_err ( CompileError :: MethodNotFound {
918
- method : method_name. clone ( ) . as_str ( ) . to_string ( ) ,
919
+ called_method : method_name. into ( ) ,
920
+ expected_signature : method_name. clone ( ) . as_str ( ) . to_string ( ) ,
919
921
type_name : self . engines . help_out ( type_id) . to_string ( ) ,
920
- matching_method_strings : vec ! [ ] ,
921
- span : method_name. span ( ) ,
922
+ matching_methods : vec ! [ ] ,
922
923
} ) ) ;
923
924
}
924
925
type_engine. decay_numeric ( handler, self . engines , type_id, & method_name. span ( ) ) ?;
@@ -1515,7 +1516,7 @@ impl<'a> TypeCheckContext<'a> {
1515
1516
continue ;
1516
1517
}
1517
1518
1518
- let key: GroupingKey = ( impl_trait. decl_id , method. implementing_for_typeid ) ;
1519
+ let key: GroupingKey = ( impl_trait. decl_id , method. implementing_for ) ;
1519
1520
1520
1521
// Prefer the method that is type-check finalized when conflicting.
1521
1522
match trait_methods. get_mut ( & key) {
@@ -1603,7 +1604,7 @@ impl<'a> TypeCheckContext<'a> {
1603
1604
let mut exact = vec ! [ ] ;
1604
1605
for r in trait_methods. values ( ) {
1605
1606
let m = decl_engine. get_function ( r) ;
1606
- if let Some ( impl_for) = m. implementing_for_typeid {
1607
+ if let Some ( impl_for) = m. implementing_for {
1607
1608
if eq_check. with_unify_ref_mut ( false ) . check ( impl_for, type_id) {
1608
1609
exact. push ( r. clone ( ) ) ;
1609
1610
}
@@ -1647,41 +1648,36 @@ impl<'a> TypeCheckContext<'a> {
1647
1648
}
1648
1649
1649
1650
#[ inline]
1650
- fn format_candidate_summaries_for_error ( & self , decl_refs : & [ DeclRefFunction ] ) -> Vec < String > {
1651
- let de = self . engines . de ( ) ;
1651
+ fn format_candidate_summaries_for_error ( engines : & Engines , decl_refs : & [ DeclRefFunction ] ) -> Vec < String > {
1652
+ let de = engines. de ( ) ;
1653
+ let fn_display = TyFunctionDisplay :: full ( ) . without_self_param_type ( ) ;
1652
1654
1653
- let mut out: Vec < String > = decl_refs
1655
+ let mut out = decl_refs
1654
1656
. iter ( )
1655
1657
. map ( |r| {
1656
1658
let m = de. get_function ( r) ;
1657
- let params = m
1658
- . parameters
1659
- . iter ( )
1660
- . map ( |p| self . engines . help_out ( p. type_argument . type_id ( ) ) . to_string ( ) )
1661
- . collect :: < Vec < _ > > ( )
1662
- . join ( ", " ) ;
1663
- let ret = self . engines . help_out ( m. return_type . type_id ( ) ) ;
1664
- let in_impl = if let Some ( for_ty) = m. implementing_for_typeid {
1665
- format ! ( " in {}" , self . engines. help_out( for_ty) )
1666
- } else {
1667
- String :: new ( )
1668
- } ;
1669
- format ! ( "{}({}) -> {}{}" , m. name. as_str( ) , params, ret, in_impl)
1659
+ fn_display. display ( & m, engines)
1670
1660
} )
1671
- . collect ( ) ;
1661
+ . collect_vec ( ) ;
1672
1662
1673
1663
out. sort ( ) ;
1674
1664
out
1675
1665
}
1676
1666
1677
1667
/// Given a `method_name` and a `type_id`, find that method on that type in the namespace.
1678
- /// `annotation_type` is the expected method return type. Requires `argument_types` because:
1668
+ ///
1669
+ /// `annotation_type` is the expected method return type.
1670
+ ///
1671
+ /// Requires `argument_types` because:
1679
1672
/// - standard operations like +, <=, etc. are called like "std::ops::<operation>" and the
1680
1673
/// actual self type of the trait implementation is determined by the passed argument type.
1681
1674
/// - we can have several implementations of generic traits for different types, that can
1682
1675
/// result in a method of a same name, but with different type arguments.
1683
1676
///
1684
1677
/// This function will emit a [CompileError::MethodNotFound] if the method is not found.
1678
+ ///
1679
+ /// Note that _method_ here means **any function associated to a type**, with or without
1680
+ /// the `self` argument.
1685
1681
#[ allow( clippy:: too_many_arguments) ]
1686
1682
pub ( crate ) fn find_method_for_type (
1687
1683
& self ,
@@ -1714,7 +1710,7 @@ impl<'a> TypeCheckContext<'a> {
1714
1710
annotation_type,
1715
1711
) ;
1716
1712
1717
- let mut matching_method_strings = HashSet :: < String > :: new ( ) ;
1713
+ let mut matching_methods = Vec :: < String > :: new ( ) ;
1718
1714
1719
1715
let mut qualified_call_path: Option < QualifiedCallPath > = None ;
1720
1716
@@ -1758,8 +1754,8 @@ impl<'a> TypeCheckContext<'a> {
1758
1754
}
1759
1755
} else {
1760
1756
// No signature-compatible candidates.
1761
- matching_method_strings
1762
- . extend ( self . format_candidate_summaries_for_error ( & matching_method_decl_refs) ) ;
1757
+ matching_methods
1758
+ . append ( & mut Self :: format_candidate_summaries_for_error ( self . engines , & matching_method_decl_refs) ) ;
1763
1759
}
1764
1760
1765
1761
// Forward an ErrorRecovery from the first argument if present.
@@ -1782,7 +1778,8 @@ impl<'a> TypeCheckContext<'a> {
1782
1778
1783
1779
// Final: MethodNotFound with formatted signature and candidates.
1784
1780
Err ( handler. emit_err ( CompileError :: MethodNotFound {
1785
- method : format ! (
1781
+ called_method : method_ident. into ( ) ,
1782
+ expected_signature : format ! (
1786
1783
"{}({}){}" ,
1787
1784
method_ident. clone( ) ,
1788
1785
arguments_types
@@ -1800,8 +1797,7 @@ impl<'a> TypeCheckContext<'a> {
1800
1797
}
1801
1798
) ,
1802
1799
type_name,
1803
- matching_method_strings : matching_method_strings. iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
1804
- span : method_ident. span ( ) ,
1800
+ matching_methods,
1805
1801
} ) )
1806
1802
}
1807
1803
0 commit comments