Skip to content

Commit

Permalink
tools/trim: prevent nil-pointer panic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Feb 1, 2022
1 parent 9aeaf70 commit 6bc922c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tools/trim/testdata/issue1087.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Issue: 1087
-- in.cue --
configs: {
key: 123
}

shared: {
param: string
derived: configs[param]
}

a: shared & {
param: "key"
}
-- out/trim --
== in.cue
configs: {
key: 123
}

shared: {
param: string
derived: configs[param]
}

a: shared & {
param: "key"
}
2 changes: 1 addition & 1 deletion tools/trim/trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (t *trimmer) addDominators(d, v *adt.Vertex, hasDisjunction bool) (doms *ad
if r, ok := c.Expr().(adt.Resolver); ok {
x, _ := t.ctx.Resolve(c.Env, r)
// Even if this is not a dominator now, descendants will be.
if x.Label.IsDef() {
if x != nil && x.Label.IsDef() {
for _, c := range x.Conjuncts {
doms.AddConjunct(c)
}
Expand Down

0 comments on commit 6bc922c

Please sign in to comment.