[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:
Shunsuke Shibayama 2025-12-05 11:05:41 +09:00 committed by GitHub
parent f3e5713d90
commit 3511b7a06b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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]

View File

@ -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;
} }