@@ -1405,7 +1405,7 @@ impl NodeInterner {
1405
1405
} ) ;
1406
1406
1407
1407
if trait_id. is_none ( ) && matches ! ( self_type, Type :: DataType ( ..) ) {
1408
- let check_self_param = true ;
1408
+ let check_self_param = false ;
1409
1409
if let Some ( existing) =
1410
1410
self . lookup_direct_method ( self_type, & method_name, check_self_param)
1411
1411
{
@@ -2395,29 +2395,40 @@ impl Methods {
2395
2395
) -> bool {
2396
2396
match interner. function_meta ( & method) . typ . instantiate ( interner) . 0 {
2397
2397
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
+ }
2403
2411
} 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
+ }
2406
2418
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
+ }
2409
2425
}
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 ( )
2417
2426
}
2418
- Type :: Error => false ,
2427
+ Type :: Error => ( ) ,
2419
2428
other => unreachable ! ( "Expected function type, found {other}" ) ,
2420
2429
}
2430
+
2431
+ false
2421
2432
}
2422
2433
}
2423
2434
0 commit comments