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

Commit 393ec28

Browse files
committed
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 <cueckoo@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
1 parent 287d43c commit 393ec28

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

cmd/cue/cmd/common.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ func (b *buildPlan) instances() iterator {
173173
}
174174
default:
175175
i = &instanceIterator{
176-
inst: b.instance,
177-
a: []*cue.Instance{b.instance},
178-
i: -1,
176+
a: []*cue.Instance{b.instance},
177+
i: -1,
179178
}
180179
b.instance = nil
181180
}

cmd/cue/cmd/testdata/script/eval_e_hidden.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ stdout '34'
77

88
cue eval -e _a tst.cue
99
stdout '34'
10+
11+
cue eval -H
12+
stdout '_a: 34'
13+
1014
-- dep.cue --
1115
package dep
1216

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cue eval pkg.cue -H
2+
cmp stdout expect-stdout
3+
4+
cue eval -H
5+
cmp stdout expect-stdout
6+
7+
cue eval file.cue -H
8+
cmp stdout expect-stdout
9+
10+
-- pkg.cue --
11+
package pkg
12+
13+
_top: 1
14+
15+
a: _h0: int
16+
17+
#foo: {
18+
_h1: string
19+
}
20+
21+
{
22+
_h2: string
23+
}
24+
25+
-- file.cue --
26+
_top: 1
27+
28+
a: _h0: int
29+
30+
#foo: {
31+
_h1: string
32+
}
33+
34+
{
35+
_h2: string
36+
}
37+
38+
-- expect-stdout --
39+
_top: 1
40+
a: {
41+
_h0: int
42+
}
43+
_h2: string
44+
#foo: {
45+
_h1: string
46+
}

cue/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ func (v Value) Unify(w Value) Value {
18151815
if v.v == nil {
18161816
return w
18171817
}
1818-
if w.v == nil {
1818+
if w.v == nil || w.v == v.v {
18191819
return v
18201820
}
18211821

internal/core/adt/feature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (f Feature) PkgID(index StringIndexer) string {
107107
}
108108
s := index.IndexToString(f.safeIndex())
109109
if p := strings.IndexByte(s, '\x00'); p >= 0 {
110-
return s[p+1:]
110+
s = s[p+1:]
111111
}
112112
return s
113113
}

0 commit comments

Comments
 (0)