mirror of https://github.com/astral-sh/ruff
[ty] do nothing with `store_expression_type` if `inner_expression_inference_state` is `Get` (#21718)
## Summary Fixes https://github.com/astral-sh/ty/issues/1688 ## Test Plan N/A
This commit is contained in:
parent
f3e5713d90
commit
3511b7a06b
|
|
@ -0,0 +1,6 @@
|
||||||
|
# This is a regression test for `store_expression_type`.
|
||||||
|
# ref: https://github.com/astral-sh/ty/issues/1688
|
||||||
|
|
||||||
|
x: int
|
||||||
|
|
||||||
|
type x[T] = x[T, U]
|
||||||
|
|
@ -7108,10 +7108,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn store_expression_type(&mut self, expression: &ast::Expr, ty: Type<'db>) {
|
fn store_expression_type(&mut self, expression: &ast::Expr, ty: Type<'db>) {
|
||||||
if self.deferred_state.in_string_annotation() {
|
if self.deferred_state.in_string_annotation()
|
||||||
|
|| self.inner_expression_inference_state.is_get()
|
||||||
|
{
|
||||||
// Avoid storing the type of expressions that are part of a string annotation because
|
// Avoid storing the type of expressions that are part of a string annotation because
|
||||||
// the expression ids don't exists in the semantic index. Instead, we'll store the type
|
// the expression ids don't exists in the semantic index. Instead, we'll store the type
|
||||||
// on the string expression itself that represents the annotation.
|
// on the string expression itself that represents the annotation.
|
||||||
|
// Also, if `inner_expression_inference_state` is `Get`, the expression type has already been stored.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue