Skip to content

Commit

Permalink
internal/core/adt: fix let closedness issue with API use
Browse files Browse the repository at this point in the history
Code did not handle lets yet. Cross checked that other places
where IsHidden is used, IsLet is used as well if applicable.

Fixes #2325

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I774560818559143d6a02f8a3f33dff8c97485f94
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/552317
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Apr 6, 2023
1 parent 1c9a3b2 commit 731ddd9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2109,12 +2109,12 @@ func TestSubsumes(t *testing.T) {
}

func TestUnify(t *testing.T) {
a := []string{"a"}
b := []string{"b"}
a := "a"
b := "b"
testCases := []struct {
value string
pathA []string
pathB []string
pathA string
pathB string
want string
}{{
value: `4`,
Expand Down Expand Up @@ -2144,12 +2144,24 @@ func TestUnify(t *testing.T) {
pathA: a,
pathB: b,
want: `{"a":"foo"}`,
}, {
// Issue #2325: let should not result in a closedness error.
value: `#T: {
...
}
b: {
let foobar = {}
_fb: foobar
}`,
pathA: "#T",
pathB: b,
want: `{}`,
}}
for _, tc := range testCases {
t.Run(tc.value, func(t *testing.T) {
v := getInstance(t, tc.value).Value()
x := v.Lookup(tc.pathA...)
y := v.Lookup(tc.pathB...)
x := v.LookupPath(ParsePath(tc.pathA))
y := v.LookupPath(ParsePath(tc.pathB))
b, err := x.Unify(y).MarshalJSON()
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 5 additions & 0 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ func (v *Vertex) IsClosedList() bool {

// TODO: return error instead of boolean? (or at least have version that does.)
func (v *Vertex) Accept(ctx *OpContext, f Feature) bool {
// TODO(v0.6): move f.IsHidden from below to here.
if f.IsLet() {
return true
}

if x, ok := v.BaseValue.(*Disjunction); ok {
for _, v := range x.Values {
if x, ok := v.(*Vertex); ok && x.Accept(ctx, f) {
Expand Down

0 comments on commit 731ddd9

Please sign in to comment.