mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
[ty] Improve invalid method calls for unmatched overloads (#18122)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
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:
parent
c066bf0127
commit
69393b2e6e
4 changed files with 132 additions and 2 deletions
|
@ -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())
|
||||
));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue