mirror of https://github.com/astral-sh/ruff
[ty] fix hover type on named expression target
This commit is contained in:
parent
d5546508cf
commit
88279ccacb
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue