[ty] Improve invalid method calls for unmatched overloads (#18122)

This makes an easy tweak to allow our diagnostics for unmatched
overloads to apply to method calls. Previously, they only worked for
function calls.

There is at least one other case worth addressing too, namely, class
literals. e.g., `type()`. We had a diagnostic snapshot test case to
track it.

Closes astral-sh/ty#274
This commit is contained in:
Andrew Gallant 2025-05-15 11:39:14 -04:00 committed by GitHub
parent c066bf0127
commit 69393b2e6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 132 additions and 2 deletions

View file

@ -1120,7 +1120,19 @@ impl<'db> CallableBinding<'db> {
String::new()
}
));
if let Some(function) = self.signature_type.into_function_literal() {
// TODO: This should probably be adapted to handle more
// types of callables[1]. At present, it just handles
// standard function and method calls.
//
// [1]: https://github.com/astral-sh/ty/issues/274#issuecomment-2881856028
let function_type_and_kind = match self.signature_type {
Type::FunctionLiteral(function) => Some(("function", function)),
Type::BoundMethod(bound_method) => {
Some(("bound method", bound_method.function(context.db())))
}
_ => None,
};
if let Some((kind, function)) = function_type_and_kind {
if let Some(overloaded_function) = function.to_overloaded(context.db()) {
if let Some(spans) = overloaded_function
.overloads
@ -1134,7 +1146,7 @@ impl<'db> CallableBinding<'db> {
}
diag.info(format_args!(
"Possible overloads for function `{}`:",
"Possible overloads for {kind} `{}`:",
function.name(context.db())
));