-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
help wantedContributions especially welcomeContributions especially welcometyMulti-file analysis & type inferenceMulti-file analysis & type inference
Description
Type::in_type_expression() already errors for some types that are invalid in type expression contexts:
ruff/crates/red_knot_python_semantic/src/types.rs
Lines 2031 to 2043 in ed2bce6
| // TODO: Should emit a diagnostic | |
| Type::KnownInstance(KnownInstanceType::Annotated) => Err(InvalidTypeExpressionError { | |
| invalid_expressions: smallvec::smallvec![InvalidTypeExpression::BareAnnotated], | |
| fallback_type: Type::Unknown, | |
| }), | |
| Type::KnownInstance(KnownInstanceType::Literal) => Err(InvalidTypeExpressionError { | |
| invalid_expressions: smallvec::smallvec![InvalidTypeExpression::BareLiteral], | |
| fallback_type: Type::Unknown, | |
| }), | |
| Type::Todo(_) => Ok(*self), | |
| _ => Ok(todo_type!( | |
| "Unsupported or invalid type in a type expression" | |
| )), |
However, there are many other types that are invalid in type expression contexts. We should remove the final fallback branch from this match statement and make it exhaustive so that all typing errors are correctly reported.
I expect that many invalid types can be covered by a single branch. Doing so might require changing this method so that its return type is std::fmt::Arguments rather than &'static str:
ruff/crates/red_knot_python_semantic/src/types.rs
Lines 2208 to 2215 in ed2bce6
| impl InvalidTypeExpression { | |
| const fn reason(self) -> &'static str { | |
| match self { | |
| Self::BareAnnotated => "`Annotated` requires at least two arguments when used in an annotation or type expression", | |
| Self::BareLiteral => "`Literal` requires at least one argument when used in a type expression", | |
| } | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcometyMulti-file analysis & type inferenceMulti-file analysis & type inference