this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/adt: fix Definition closedness bug in API

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>

+25 -17
+24 -16
cue/types_test.go
··· 31 31 "cuelang.org/go/internal/astinternal" 32 32 "cuelang.org/go/internal/core/adt" 33 33 "cuelang.org/go/internal/core/debug" 34 + "cuelang.org/go/internal/cuetest" 35 + "cuelang.org/go/internal/tdtest" 34 36 ) 35 37 36 38 func getInstance(t *testing.T, body string) *Instance { ··· 2111 2113 func TestUnify(t *testing.T) { 2112 2114 a := "a" 2113 2115 b := "b" 2114 - testCases := []struct { 2116 + type testCase struct { 2115 2117 value string 2116 2118 pathA string 2117 2119 pathB string 2118 2120 want string 2119 - }{{ 2121 + } 2122 + testCases := []testCase{{ 2120 2123 value: `4`, 2121 2124 want: `4`, 2122 2125 }, { ··· 2156 2159 pathA: "#T", 2157 2160 pathB: b, 2158 2161 want: `{}`, 2162 + }, { 2163 + value: ` 2164 + a: #A: "foo" 2165 + #B: {...} 2166 + `, 2167 + pathA: a, 2168 + pathB: "#B", 2169 + want: `{}`, 2159 2170 }} 2160 - for _, tc := range testCases { 2161 - t.Run(tc.value, func(t *testing.T) { 2162 - v := getInstance(t, tc.value).Value() 2163 - x := v.LookupPath(ParsePath(tc.pathA)) 2164 - y := v.LookupPath(ParsePath(tc.pathB)) 2165 - b, err := x.Unify(y).MarshalJSON() 2166 - if err != nil { 2167 - t.Fatal(err) 2168 - } 2169 - if got := string(b); got != tc.want { 2170 - t.Errorf("got %v; want %v", got, tc.want) 2171 - } 2172 - }) 2173 - } 2171 + // TODO(tdtest): use cuetest.Run when supported. 2172 + tdtest.Run(t, testCases, func(t *cuetest.T, tc *testCase) { 2173 + v := getInstance(t.T, tc.value).Value() 2174 + x := v.LookupPath(ParsePath(tc.pathA)) 2175 + y := v.LookupPath(ParsePath(tc.pathB)) 2176 + b, err := x.Unify(y).MarshalJSON() 2177 + if err != nil { 2178 + t.Fatal(err) 2179 + } 2180 + t.Equal(string(b), tc.want) 2181 + }) 2174 2182 } 2175 2183 2176 2184 func TestEquals(t *testing.T) {
+1 -1
internal/core/adt/closed.go
··· 480 480 o := s.StructLit 481 481 env := s.Env 482 482 483 - if isRegular && (len(o.Additional) > 0 || o.IsOpen) { 483 + if len(o.Additional) > 0 || o.IsOpen { 484 484 return true 485 485 } 486 486