mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-12 14:48:16 +00:00
[ty] Emit error for invalid binary operations in type expressions (#18991)
## Summary This PR adds diagnostic for invalid binary operators in type expressions. It should close https://github.com/astral-sh/ty/issues/706 if merged. Please feel free to suggest better wordings for the diagnostic message. ## Test Plan I modified `mdtest/annotations/invalid.md` and added a test for each binary operator, and fixed tests that was broken by the new diagnostic.
This commit is contained in:
parent
9469a982cc
commit
0ec2ad2fa5
4 changed files with 46 additions and 2 deletions
|
@ -8416,8 +8416,17 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
|||
UnionType::from_elements(self.db(), [left_ty, right_ty])
|
||||
}
|
||||
// anything else is an invalid annotation:
|
||||
_ => {
|
||||
op => {
|
||||
self.infer_binary_expression(binary);
|
||||
if let Some(mut diag) = self.report_invalid_type_expression(
|
||||
expression,
|
||||
format_args!(
|
||||
"Invalid binary operator `{}` in type annotation",
|
||||
op.as_str()
|
||||
),
|
||||
) {
|
||||
diag.info("Did you mean to use `|`?");
|
||||
}
|
||||
Type::unknown()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue