@@ -1405,7 +1405,7 @@ impl NodeInterner {
14051405 } ) ;
14061406
14071407 if trait_id. is_none ( ) && matches ! ( self_type, Type :: DataType ( ..) ) {
1408- let check_self_param = true ;
1408+ let check_self_param = false ;
14091409 if let Some ( existing) =
14101410 self . lookup_direct_method ( self_type, & method_name, check_self_param)
14111411 {
@@ -2395,29 +2395,40 @@ impl Methods {
23952395 ) -> bool {
23962396 match interner. function_meta ( & method) . typ . instantiate ( interner) . 0 {
23972397 Type :: Function ( args, _, _, _) => {
2398- let target_type = if check_self_param {
2399- let Some ( object) = args. first ( ) else {
2400- return false ;
2401- } ;
2402- object
2398+ if check_self_param {
2399+ if let Some ( object) = args. first ( ) {
2400+ if object. unify ( typ) . is_ok ( ) {
2401+ return true ;
2402+ }
2403+
2404+ // Handle auto-dereferencing `&mut T` into `T`
2405+ if let Type :: MutableReference ( object) = object {
2406+ if object. unify ( typ) . is_ok ( ) {
2407+ return true ;
2408+ }
2409+ }
2410+ }
24032411 } else {
2404- method_type
2405- } ;
2412+ // We still need to make sure the method is for the given type
2413+ // (this might be false if for example a method for `Struct<i32>` was added but
2414+ // now we are looking for a method in `Struct<i64>`)
2415+ if method_type. unify ( typ) . is_ok ( ) {
2416+ return true ;
2417+ }
24062418
2407- if target_type. unify ( typ) . is_ok ( ) {
2408- return true ;
2419+ // Handle auto-dereferencing `&mut T` into `T`
2420+ if let Type :: MutableReference ( method_type) = method_type {
2421+ if method_type. unify ( typ) . is_ok ( ) {
2422+ return true ;
2423+ }
2424+ }
24092425 }
2410-
2411- // Handle auto-dereferencing `&mut T` into `T`
2412- let Type :: MutableReference ( target_type) = target_type else {
2413- return false ;
2414- } ;
2415-
2416- target_type. unify ( typ) . is_ok ( )
24172426 }
2418- Type :: Error => false ,
2427+ Type :: Error => ( ) ,
24192428 other => unreachable ! ( "Expected function type, found {other}" ) ,
24202429 }
2430+
2431+ false
24212432 }
24222433}
24232434
0 commit comments