Skip to content

Commit edfa984

Browse files
authored
merger: handle ident load (#2014)
**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.
1 parent d172a22 commit edfa984

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

merger/fix.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func FixLoads(f *rule.File, knownLoads []rule.LoadInfo) {
8888
} else {
8989
return
9090
}
91+
} else if ae, ok := x.(*bzl.AssignExpr); ok {
92+
if id, ok := ae.RHS.(*bzl.Ident); ok {
93+
idents = append(idents, id)
94+
} else {
95+
return
96+
}
9197
} else {
9298
return
9399
}

merger/fix_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ foo_binary(
235235
name = "a",
236236
field = magic_struct.member,
237237
)
238+
`,
239+
},
240+
"assignment expr rhs": {
241+
input: `foo_binary(
242+
name = "a",
243+
field = magic_macro,
244+
)
245+
`,
246+
want: `load("@bar", "magic_macro")
247+
load("@foo", "foo_binary")
248+
249+
foo_binary(
250+
name = "a",
251+
field = magic_macro,
252+
)
238253
`,
239254
},
240255
} {

0 commit comments

Comments
 (0)