Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue/cmd/cue: fix regression for -H flag
Browse files Browse the repository at this point in the history
Instance iterator accidentally would include instance twice
in some cases, which caused it to be unified into a new
anonoymous package for which hidden fields would not
be shown.

Also adds an optimization in Unify to return one of
the arguments if they are identical, instead of unifying.

The setting the variable instead of returning makes using
a debugger easier.

Change-Id: I311c0d2dcb50d277a47eaaae352e5fb467935eba
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9844
Reviewed-by: CUE cueckoo <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mpvl committed May 19, 2021
1 parent 287d43c commit 393ec28
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ func (b *buildPlan) instances() iterator {
}
default:
i = &instanceIterator{
inst: b.instance,
a: []*cue.Instance{b.instance},
i: -1,
a: []*cue.Instance{b.instance},
i: -1,
}
b.instance = nil
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/cue/cmd/testdata/script/eval_e_hidden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ stdout '34'

cue eval -e _a tst.cue
stdout '34'

cue eval -H
stdout '_a: 34'

-- dep.cue --
package dep

Expand Down
46 changes: 46 additions & 0 deletions cmd/cue/cmd/testdata/script/hidden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cue eval pkg.cue -H
cmp stdout expect-stdout

cue eval -H
cmp stdout expect-stdout

cue eval file.cue -H
cmp stdout expect-stdout

-- pkg.cue --
package pkg

_top: 1

a: _h0: int

#foo: {
_h1: string
}

{
_h2: string
}

-- file.cue --
_top: 1

a: _h0: int

#foo: {
_h1: string
}

{
_h2: string
}

-- expect-stdout --
_top: 1
a: {
_h0: int
}
_h2: string
#foo: {
_h1: string
}
2 changes: 1 addition & 1 deletion cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ func (v Value) Unify(w Value) Value {
if v.v == nil {
return w
}
if w.v == nil {
if w.v == nil || w.v == v.v {
return v
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (f Feature) PkgID(index StringIndexer) string {
}
s := index.IndexToString(f.safeIndex())
if p := strings.IndexByte(s, '\x00'); p >= 0 {
return s[p+1:]
s = s[p+1:]
}
return s
}
Expand Down

0 comments on commit 393ec28

Please sign in to comment.