Skip to content

Commit b95b211

Browse files
committed
tools/trim: only consider defaults when we're not ignoring the conjunct
If a conjunct has been marked to be ignored, then we should not consider it even if it is a default for a disjunction. This change does not prevent trimming of code due to defaults: there's a specific defaults.txtar (which is unchanged) which shows the existence of defaults can still lead to trimming. Fixes: #3995 Change-Id: I0a693f2f14caf744f4d04ba39293b3871acdd71d Signed-off-by: Matthew Sackman <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1219302 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent c7cc1a8 commit b95b211

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

tools/trim/testdata/64.txtar

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Disjunctions.
2+
3+
If line 2 wasn't present,
4+
5+
out: #Schema & {type: "A"}
6+
7+
correctly gets simplified to
8+
9+
out: #Schema & _
10+
11+
because of the default.
12+
13+
However, with line 2 present, simplifying `out` in the same way is incorrect.
14+
15+
Note that v2 gets this wrong.
16+
17+
-- a.cue --
18+
#Schema: {type: *"A" | string}
19+
#Schema: {type: "A"} | {type: "CNAME"}
20+
out: #Schema & {type: "A"}
21+
-- out/trim-v3 --
22+
== a.cue
23+
#Schema: {type: *"A" | string}
24+
#Schema: {type: "A"} | {type: "CNAME"}
25+
out: #Schema & {type: "A"}
26+
-- diff/-out/trim-v3<==>+out/trim --
27+
diff old new
28+
--- old
29+
+++ new
30+
@@ -1,4 +1,4 @@
31+
== a.cue
32+
#Schema: {type: *"A" | string}
33+
#Schema: {type: "A"} | {type: "CNAME"}
34+
-out: #Schema & {}
35+
+out: #Schema & {type: "A"}
36+
-- out/trim-v3-noshare --
37+
== a.cue
38+
#Schema: {type: *"A" | string}
39+
#Schema: {type: "A"} | {type: "CNAME"}
40+
out: #Schema & {type: "A"}
41+
-- diff/-out/trim-v3-noshare<==>+out/trim --
42+
diff old new
43+
--- old
44+
+++ new
45+
@@ -1,4 +1,4 @@
46+
== a.cue
47+
#Schema: {type: *"A" | string}
48+
#Schema: {type: "A"} | {type: "CNAME"}
49+
-out: #Schema & {}
50+
+out: #Schema & {type: "A"}
51+
-- out/trim --
52+
== a.cue
53+
#Schema: {type: *"A" | string}
54+
#Schema: {type: "A"} | {type: "CNAME"}
55+
out: #Schema & {}

tools/trim/trimv3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ func (t *trimmerV3) findRedundancies(v *adt.Vertex, keepAll bool) {
728728
}
729729
}
730730

731-
if disj, ok := expr.(*adt.DisjunctionExpr); ok && disj.HasDefaults {
731+
if disj, ok := expr.(*adt.DisjunctionExpr); !nm.ignoreConjunct && ok && disj.HasDefaults {
732732
defaultCount := 0
733733
matchingDefaultCount := 0
734734
for _, branch := range disj.Values {

0 commit comments

Comments
 (0)