Skip to content

Commit ff654dc

Browse files
committed
cue: do not unify "accept" schema with result in UnifyAccept
EvalV2 used the accept schema solely for validation, while EvalV3 would unify the accept schema with the result. This would cause more conjuncts to be unified with the schema, which caused some tools using the API to report more conjuncts. EvalV3 is now more in line with EvalV2. This fixes most of Issue 3847, but there is an unrelated issue that affects it that we will address in a separate CL. Issue #3847 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I918b6b7fa84e862378f19a69a509e009c6028231 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1212214 Reviewed-by: Matthew Sackman <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 2b82584 commit ff654dc

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

cue/types.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -1766,24 +1766,20 @@ func (v Value) UnifyAccept(w Value, accept Value) Value {
17661766
n.AddConjunct(cv)
17671767
n.AddConjunct(cw)
17681768

1769-
n.Finalize(ctx)
1770-
1771-
n.Parent = v.v.Parent
1772-
n.Label = v.v.Label
1773-
1774-
if err := n.Err(ctx); err != nil {
1775-
return makeValue(v.idx, n, v.parent_)
1776-
}
1777-
if err := allowed(ctx, accept.v, n); err != nil {
1778-
return newErrValue(accept, err)
1779-
}
1780-
17811769
case internal.EvalV3:
17821770
n.AddOpenConjunct(ctx, v.v)
17831771
n.AddOpenConjunct(ctx, w.v)
1784-
ca := adt.MakeRootConjunct(nil, accept.v)
1785-
n.AddConjunct(ca)
1786-
n.Finalize(ctx)
1772+
}
1773+
n.Finalize(ctx)
1774+
1775+
n.Parent = v.v.Parent
1776+
n.Label = v.v.Label
1777+
1778+
if err := n.Err(ctx); err != nil {
1779+
return makeValue(v.idx, n, v.parent_)
1780+
}
1781+
if err := allowed(ctx, accept.v, n); err != nil {
1782+
return newErrValue(accept, err)
17871783
}
17881784

17891785
return makeValue(v.idx, n, v.parent_)

cue/types_test.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -2409,8 +2409,9 @@ func TestUnifyAccept(t *testing.T) {
24092409
// Issue #3829
24102410
func TestConjunctDedup(t *testing.T) {
24112411
type testCase struct {
2412-
value string
2413-
want string
2412+
value string
2413+
want string
2414+
conjuncts string // only tested if not ""
24142415
}
24152416
testCases := []testCase{{
24162417
value: `
@@ -2423,6 +2424,16 @@ func TestConjunctDedup(t *testing.T) {
24232424
f1: int
24242425
f: string
24252426
}`,
2427+
}, {
2428+
// Issue #3847
2429+
value: `
2430+
import "struct"
2431+
2432+
#t: struct.MinFields(4)
2433+
#t: struct.MaxFields(9)
2434+
`,
2435+
want: `struct.MinFields(4) & struct.MaxFields(9)`,
2436+
conjuncts: `[struct.MinFields(4) struct.MaxFields(9)]`,
24262437
}}
24272438

24282439
matrix := cuetdtest.FullMatrix
@@ -2446,6 +2457,12 @@ func TestConjunctDedup(t *testing.T) {
24462457
}
24472458
}
24482459
t.Equal(fmt.Sprint(v), tc.want)
2460+
2461+
_, args = v.Expr()
2462+
if tc.conjuncts == "" {
2463+
return
2464+
}
2465+
t.Equal(fmt.Sprint(args), tc.conjuncts)
24492466
})
24502467
})
24512468
}

encoding/openapi/testdata/embed.txtar

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#skip-v3
2-
#skip-v3-noshare
31
-- in.cue --
42
#Foo: string
53

encoding/openapi/testdata/struct.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#skip-v3-noshare
1+
#skip-v3
22
-- in.cue --
33
import "struct"
44

0 commit comments

Comments
 (0)