From 393ec282e7ee0c636e5c1165947aadfd3557b970 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Tue, 18 May 2021 13:31:24 +0200 Subject: [PATCH] cue/cmd/cue: fix regression for -H flag 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 Reviewed-by: Paul Jolly --- cmd/cue/cmd/common.go | 5 +- cmd/cue/cmd/testdata/script/eval_e_hidden.txt | 4 ++ cmd/cue/cmd/testdata/script/hidden.txt | 46 +++++++++++++++++++ cue/types.go | 2 +- internal/core/adt/feature.go | 2 +- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 cmd/cue/cmd/testdata/script/hidden.txt diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go index 31c2f6453..940118252 100644 --- a/cmd/cue/cmd/common.go +++ b/cmd/cue/cmd/common.go @@ -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 } diff --git a/cmd/cue/cmd/testdata/script/eval_e_hidden.txt b/cmd/cue/cmd/testdata/script/eval_e_hidden.txt index 0148499f4..3f0a3d80b 100644 --- a/cmd/cue/cmd/testdata/script/eval_e_hidden.txt +++ b/cmd/cue/cmd/testdata/script/eval_e_hidden.txt @@ -7,6 +7,10 @@ stdout '34' cue eval -e _a tst.cue stdout '34' + +cue eval -H +stdout '_a: 34' + -- dep.cue -- package dep diff --git a/cmd/cue/cmd/testdata/script/hidden.txt b/cmd/cue/cmd/testdata/script/hidden.txt new file mode 100644 index 000000000..32ecf7a8d --- /dev/null +++ b/cmd/cue/cmd/testdata/script/hidden.txt @@ -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 +} diff --git a/cue/types.go b/cue/types.go index 636fe5222..3502e4aed 100644 --- a/cue/types.go +++ b/cue/types.go @@ -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 } diff --git a/internal/core/adt/feature.go b/internal/core/adt/feature.go index 2df36569e..a09931408 100644 --- a/internal/core/adt/feature.go +++ b/internal/core/adt/feature.go @@ -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 }