[ty] fix hover type on named expression target

This commit is contained in:
Carl Meyer 2025-12-12 09:19:24 -08:00
parent d5546508cf
commit 88279ccacb
No known key found for this signature in database
GPG Key ID: 2D1FB7916A52E121
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");
}
#[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 {
fn hover(&self) -> String {
use std::fmt::Write;

View File

@ -8164,10 +8164,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
value,
} = named;
self.infer_expression(target, TypeContext::default());
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
})
}