[ty] fix hover type on named expression target (#21952)

## Summary

What it says on the tin.

## Test Plan

Added hover test.
This commit is contained in:
Carl Meyer 2025-12-12 09:30:50 -08:00 committed by GitHub
parent 90b29c9e87
commit 69d1bfbebc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View File

@ -3624,6 +3624,37 @@ def function():
assert_snapshot!(test.hover(), @"Hover provided no content"); assert_snapshot!(test.hover(), @"Hover provided no content");
} }
#[test]
fn hover_named_expression_target() {
let test = CursorTest::builder()
.source(
"mymod.py",
r#"
if a<CURSOR> := 10:
pass
"#,
)
.build();
assert_snapshot!(test.hover(), @r###"
Literal[10]
---------------------------------------------
```python
Literal[10]
```
---------------------------------------------
info[hover]: Hovered content is
--> mymod.py:2:4
|
2 | if a := 10:
| ^- Cursor offset
| |
| source
3 | pass
|
"###);
}
impl CursorTest { impl CursorTest {
fn hover(&self) -> String { fn hover(&self) -> String {
use std::fmt::Write; use std::fmt::Write;

View File

@ -8164,10 +8164,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
value, value,
} = named; } = named;
self.infer_expression(target, TypeContext::default());
self.add_binding(named.target.as_ref().into(), definition, |builder, tcx| { self.add_binding(named.target.as_ref().into(), definition, |builder, tcx| {
builder.infer_expression(value, tcx) let ty = builder.infer_expression(value, tcx);
builder.store_expression_type(target, ty);
ty
}) })
} }