Skip to content

Commit 6bc922c

Browse files
committed
tools/trim: prevent nil-pointer panic
Fixes #1087 Change-Id: I471969c6f75361e39f706083eb23a0b005be92ad Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/532314 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
1 parent 9aeaf70 commit 6bc922c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tools/trim/testdata/issue1087.txtar

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#Issue: 1087
2+
-- in.cue --
3+
configs: {
4+
key: 123
5+
}
6+
7+
shared: {
8+
param: string
9+
derived: configs[param]
10+
}
11+
12+
a: shared & {
13+
param: "key"
14+
}
15+
-- out/trim --
16+
== in.cue
17+
configs: {
18+
key: 123
19+
}
20+
21+
shared: {
22+
param: string
23+
derived: configs[param]
24+
}
25+
26+
a: shared & {
27+
param: "key"
28+
}

tools/trim/trim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (t *trimmer) addDominators(d, v *adt.Vertex, hasDisjunction bool) (doms *ad
216216
if r, ok := c.Expr().(adt.Resolver); ok {
217217
x, _ := t.ctx.Resolve(c.Env, r)
218218
// Even if this is not a dominator now, descendants will be.
219-
if x.Label.IsDef() {
219+
if x != nil && x.Label.IsDef() {
220220
for _, c := range x.Conjuncts {
221221
doms.AddConjunct(c)
222222
}

0 commit comments

Comments
 (0)