Skip to content

Commit

Permalink
internal/core/adt: fix Definition closedness bug in API
Browse files Browse the repository at this point in the history
Open structs or structs with ellipsis should always allow
fields, not just regular ones.
The question is if this is really the case when we disallow
definitions in closed struct by default, but it seems fair
enough to allow this until this is the case as it is consistent
with CUE's behavior.

Fixes #2320
Issue #543

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I25a42948f569e81ddacc74c7467c98a287861bea
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/552331
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mpvl committed Apr 11, 2023
1 parent 410eea1 commit c3c8eb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"cuelang.org/go/internal/astinternal"
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/debug"
"cuelang.org/go/internal/cuetest"
"cuelang.org/go/internal/tdtest"
)

func getInstance(t *testing.T, body string) *Instance {
Expand Down Expand Up @@ -2111,12 +2113,13 @@ func TestSubsumes(t *testing.T) {
func TestUnify(t *testing.T) {
a := "a"
b := "b"
testCases := []struct {
type testCase struct {
value string
pathA string
pathB string
want string
}{{
}
testCases := []testCase{{
value: `4`,
want: `4`,
}, {
Expand Down Expand Up @@ -2156,21 +2159,26 @@ func TestUnify(t *testing.T) {
pathA: "#T",
pathB: b,
want: `{}`,
}, {
value: `
a: #A: "foo"
#B: {...}
`,
pathA: a,
pathB: "#B",
want: `{}`,
}}
for _, tc := range testCases {
t.Run(tc.value, func(t *testing.T) {
v := getInstance(t, tc.value).Value()
x := v.LookupPath(ParsePath(tc.pathA))
y := v.LookupPath(ParsePath(tc.pathB))
b, err := x.Unify(y).MarshalJSON()
if err != nil {
t.Fatal(err)
}
if got := string(b); got != tc.want {
t.Errorf("got %v; want %v", got, tc.want)
}
})
}
// TODO(tdtest): use cuetest.Run when supported.
tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) {
v := getInstance(t.T, tc.value).Value()
x := v.LookupPath(ParsePath(tc.pathA))
y := v.LookupPath(ParsePath(tc.pathB))
b, err := x.Unify(y).MarshalJSON()
if err != nil {
t.Fatal(err)
}
t.Equal(string(b), tc.want)
})
}

func TestEquals(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/adt/closed.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func verifyArc(ctx *OpContext, s *StructInfo, f Feature, label Value) bool {
o := s.StructLit
env := s.Env

if isRegular && (len(o.Additional) > 0 || o.IsOpen) {
if len(o.Additional) > 0 || o.IsOpen {
return true
}

Expand Down

0 comments on commit c3c8eb7

Please sign in to comment.