@@ -4,14 +4,15 @@ use std::path::{Path, PathBuf};
44
55use erg_common:: config:: Input ;
66use erg_common:: consts:: { ERG_MODE , PYTHON_MODE } ;
7- use erg_common:: dict;
87use erg_common:: error:: { ErrorCore , Location , SubMessage } ;
98use erg_common:: levenshtein;
109use erg_common:: set:: Set ;
1110use erg_common:: traits:: { Locational , NoTypeDisplay , Stream } ;
1211use erg_common:: triple:: Triple ;
1312use erg_common:: Str ;
14- use erg_common:: { fmt_option, fmt_slice, log, option_enum_unwrap, set, switch_lang} ;
13+ use erg_common:: {
14+ dict, fmt_option, fmt_slice, get_hash, log, option_enum_unwrap, set, switch_lang,
15+ } ;
1516
1617use erg_parser:: ast:: { self , Identifier , VarName } ;
1718use erg_parser:: token:: Token ;
@@ -1024,20 +1025,23 @@ impl Context {
10241025 let coerced = self
10251026 . coerce ( obj. t ( ) , & ( ) )
10261027 . map_err ( |mut errs| errs. remove ( 0 ) ) ?;
1027- if & coerced == obj. ref_t ( ) {
1028- Err ( TyCheckError :: no_attr_error (
1029- self . cfg . input . clone ( ) ,
1030- line ! ( ) as usize ,
1031- attr_name. loc ( ) ,
1032- namespace. name . to_string ( ) ,
1033- obj. ref_t ( ) ,
1034- attr_name. inspect ( ) ,
1035- self . get_similar_attr ( obj. ref_t ( ) , attr_name. inspect ( ) ) ,
1036- ) )
1037- } else {
1028+ if & coerced != obj. ref_t ( ) {
1029+ let hash = get_hash ( obj. ref_t ( ) ) ;
10381030 obj. ref_t ( ) . coerce ( ) ;
1039- self . search_method_info ( obj, attr_name, pos_args, kw_args, input, namespace)
1031+ if get_hash ( obj. ref_t ( ) ) != hash {
1032+ return self
1033+ . search_method_info ( obj, attr_name, pos_args, kw_args, input, namespace) ;
1034+ }
10401035 }
1036+ Err ( TyCheckError :: no_attr_error (
1037+ self . cfg . input . clone ( ) ,
1038+ line ! ( ) as usize ,
1039+ attr_name. loc ( ) ,
1040+ namespace. name . to_string ( ) ,
1041+ obj. ref_t ( ) ,
1042+ attr_name. inspect ( ) ,
1043+ self . get_similar_attr ( obj. ref_t ( ) , attr_name. inspect ( ) ) ,
1044+ ) )
10411045 }
10421046
10431047 fn validate_visibility (
@@ -1263,12 +1267,13 @@ impl Context {
12631267 return Err ( self . not_callable_error ( obj, attr_name, instance, None ) ) ;
12641268 }
12651269 if sub != Never {
1270+ let hash = get_hash ( instance) ;
12661271 instance. coerce ( ) ;
12671272 if instance. is_quantified_subr ( ) {
12681273 let instance = self . instantiate ( instance. clone ( ) , obj) ?;
12691274 self . substitute_call ( obj, attr_name, & instance, pos_args, kw_args) ?;
12701275 return Ok ( SubstituteResult :: Coerced ( instance) ) ;
1271- } else {
1276+ } else if get_hash ( instance ) != hash {
12721277 return self
12731278 . substitute_call ( obj, attr_name, instance, pos_args, kw_args) ;
12741279 }
0 commit comments