Skip to content

Commit

Permalink
tools/trim: fix defaults bug
Browse files Browse the repository at this point in the history
handle defaults in both directions.

This really seems to be a sumbsumption bug more than anything,
but this makes trim more robust either way.

Fixes #759

Change-Id: Iaadaf2c628f0e9a3a8edb268abdeb1d991adde18
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8703
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
  • Loading branch information
mpvl committed Feb 13, 2021
1 parent 1d9aa17 commit af5ea97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tools/trim/testdata/defaults.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
-- in.cue --
foo: [string]: a: *1 | int
foo: b: a: 1
domToSub: {
foo: [string]: a: *1 | int
foo: b: a: 1
}

// Issue #759
subToDom: {
#maybeString: {ip?: string}
something: ip: *"default" | string
something: #maybeString
}
-- out/trim --
== in.cue
foo: [string]: a: *1 | int
foo: b: {}
domToSub: {
foo: [string]: a: *1 | int
foo: b: {}
}

// Issue #759
subToDom: {
#maybeString: {ip?: string}
something: ip: *"default" | string
something: #maybeString
}
5 changes: 5 additions & 0 deletions tools/trim/trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (t *trimmer) findSubordinates(v *adt.Vertex) (result int) {
doms.Finalize(t.ctx)
doms = doms.Default()

// This should normally not be necessary, as subsume should catch this.
// But as we already take the default value for doms, it doesn't hurt to
// do it.
v = v.Default()

// This is not necessary, but seems like it may result in more
// user-friendly semantics.
if doms.IsErr() || v.IsErr() {
Expand Down

0 comments on commit af5ea97

Please sign in to comment.