Skip to content

Commit

Permalink
merger: handle ident load (#2014)
Browse files Browse the repository at this point in the history
**What type of PR is this?**
Bug fix

**What package or component does this PR mostly affect?**
merger

**What does this PR do? Why is it needed?**
I found that used idents in assignment expression rhs position have
their load statements removed. This PR adds those idents to used symbols
collection in `FixLoads` fn.
  • Loading branch information
chasestarr authored Jan 16, 2025
1 parent d172a22 commit edfa984
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions merger/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func FixLoads(f *rule.File, knownLoads []rule.LoadInfo) {
} else {
return
}
} else if ae, ok := x.(*bzl.AssignExpr); ok {
if id, ok := ae.RHS.(*bzl.Ident); ok {
idents = append(idents, id)
} else {
return
}
} else {
return
}
Expand Down
15 changes: 15 additions & 0 deletions merger/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ foo_binary(
name = "a",
field = magic_struct.member,
)
`,
},
"assignment expr rhs": {
input: `foo_binary(
name = "a",
field = magic_macro,
)
`,
want: `load("@bar", "magic_macro")
load("@foo", "foo_binary")
foo_binary(
name = "a",
field = magic_macro,
)
`,
},
} {
Expand Down

0 comments on commit edfa984

Please sign in to comment.