Skip to content

Commit 461481e

Browse files
committed
Fix double-$ prefix in assignment dependency tracking
1 parent aae5193 commit 461481e

2 files changed

Lines changed: 2 additions & 19 deletions

File tree

docs/todo/bugs.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,3 @@ handle this automatically.
2222
`tests/psalm_assertions/method_call.php` (out of scope until
2323
upstream stubs land).
2424

25-
26-
## B17. Double-`$` prefix in assignment dependency tracking
27-
28-
`src/completion/variable/forward_walk.rs` L5972-5977
29-
(`collect_expr_assignment_deps`) and L5985-5987
30-
(`collect_rhs_variables`) use `format!("${}", dv.name)` to
31-
construct variable names. Since `dv.name` already includes the
32-
`$` prefix (e.g. `"$fn"`), this produces `"$$fn"`. The bug is
33-
latent because both the LHS key and the RHS set values are
34-
consistently double-prefixed, so dependency tracking still
35-
works. However, any code that compares these names against
36-
normally-prefixed variable names (single `$`) would fail to
37-
match.
38-
39-
**Fix:** Remove the `format!("${}", ...)` wrapper and use
40-
`dv.name.to_string()` directly in both functions.
41-

src/completion/variable/forward_walk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5970,7 +5970,7 @@ fn collect_expr_assignment_deps(
59705970
if let Expression::Assignment(assign) = expr
59715971
&& let Expression::Variable(Variable::Direct(dv)) = assign.lhs
59725972
{
5973-
let lhs_name = format!("${}", dv.name);
5973+
let lhs_name = dv.name.to_string();
59745974
let mut rhs_vars = HashSet::new();
59755975
collect_rhs_variables(assign.rhs, &mut rhs_vars);
59765976
deps.entry(lhs_name).or_default().extend(rhs_vars);
@@ -5983,7 +5983,7 @@ fn collect_rhs_variables(expr: &Expression<'_>, vars: &mut HashSet<String>) {
59835983

59845984
match expr {
59855985
Expression::Variable(Variable::Direct(dv)) => {
5986-
vars.insert(format!("${}", dv.name));
5986+
vars.insert(dv.name.to_string());
59875987
}
59885988
Expression::Binary(binary) => {
59895989
collect_rhs_variables(binary.lhs, vars);

0 commit comments

Comments
 (0)