Small refactor

This commit is contained in:
Matthew Mckee 2025-10-21 23:20:18 +01:00
parent c09cd6c9d0
commit 962c1f70e1

View file

@ -9045,27 +9045,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
}; };
// The reflected dunder has priority if the right-hand side is a strict subclass of the left-hand side. // The reflected dunder has priority if the right-hand side is a strict subclass of the left-hand side.
if left != right && right.is_subtype_of(db, left) { if left != right && right.is_subtype_of(db, left) {
let first_call = call_dunder(op.reflect(), right, left); call_dunder(op.reflect(), right, left)
.or_else(|e| call_dunder(op, left, right)
match first_call { .map_err(|_| e))
Ok(ty) => Ok(ty),
Err(e) => match call_dunder(op, left, right) {
Ok(ty) => Ok(ty),
Err(_) => Err(e),
},
}
} else { } else {
let first_call = call_dunder(op, left, right); call_dunder(op, left, right)
.or_else(|e| call_dunder(op.reflect(), right, left)
match first_call { .map_err(|_| e))
Ok(ty) => Ok(ty),
Err(e) => match call_dunder(op.reflect(), right, left) {
Ok(ty) => Ok(ty),
Err(_) => Err(e),
},
}
} }
.or_else(|e| { .or_else(|e| {
// When no appropriate method returns any value other than NotImplemented, // When no appropriate method returns any value other than NotImplemented,