Skip to content

Commit 0e56b82

Browse files
committed
internal/core/export: don't add empty temp struct
Fixes bug where a temporary struct was added even if the underlying value itself was not a struct. Fixes #1284 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: I29c615c4670594d00725dd54e13ca96b3b33e304 Signed-off-by: Marcel van Lohuizen <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/527841 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 75c3d6b commit 0e56b82

File tree

2 files changed

+112
-8
lines changed

2 files changed

+112
-8
lines changed

internal/core/export/expr.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct,
191191
s.Elts = append(s.Elts, st.Elts...)
192192
return s
193193
}
194-
case 2:
195-
if len(e.attrs) > 0 {
196-
break
197-
}
198-
// Simplify.
199-
e.conjuncts = append(e.conjuncts, e.embed...)
200-
return ast.NewBinExpr(token.AND, e.conjuncts...)
201194
}
202195
}
203196

@@ -258,7 +251,13 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct,
258251
// return ast.NewCall(ast.NewIdent("close"), s)
259252
// }
260253

261-
e.conjuncts = append(e.conjuncts, s)
254+
switch {
255+
case len(e.conjuncts) == 0:
256+
return s
257+
258+
case len(e.structs) > 0, len(s.Elts) > 0:
259+
e.conjuncts = append(e.conjuncts, s)
260+
}
262261

263262
return ast.NewBinExpr(token.AND, e.conjuncts...)
264263
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
-- in.cue --
2+
a0: {
3+
l: ["a",...]
4+
l: ["a","b",...]
5+
}
6+
a1: {
7+
l: [...]
8+
l: ["a",...]
9+
l: ["a","b",...]
10+
}
11+
a2: {
12+
l: [...]
13+
l: ["a",...]
14+
l: ["a","b",...]
15+
l: {}
16+
}
17+
a3: {
18+
l: [...]
19+
l: ["a",...]
20+
l: ["a","b",...]
21+
l: { _ }
22+
}
23+
a4: {
24+
l: [...]
25+
l: ["a",...]
26+
l: ["a","b",...]
27+
l: { _, #foo: 1 }
28+
l: { _, @decl(1) }
29+
}
30+
-- out/definition --
31+
a0: {
32+
l: ["a", ...] & ["a", "b", ...]
33+
}
34+
a1: {
35+
l: [...] & ["a", ...] & ["a", "b", ...]
36+
}
37+
a2: {
38+
l: [...] & ["a", ...] & ["a", "b", ...] & {}
39+
}
40+
a3: {
41+
l: [...] & ["a", ...] & ["a", "b", ...] & {
42+
_
43+
}
44+
}
45+
a4: {
46+
l: [...] & ["a", ...] & ["a", "b", ...] & {
47+
@decl(1)
48+
_
49+
#foo: 1
50+
}
51+
}
52+
-- out/doc --
53+
[]
54+
[a0]
55+
[a0 l]
56+
[a0 l 0]
57+
[a0 l 1]
58+
[a1]
59+
[a1 l]
60+
[a1 l 0]
61+
[a1 l 1]
62+
[a2]
63+
[a2 l]
64+
[a2 l 0]
65+
[a2 l 1]
66+
[a3]
67+
[a3 l]
68+
[a3 l 0]
69+
[a3 l 1]
70+
[a4]
71+
[a4 l]
72+
[a4 l #foo]
73+
[a4 l 0]
74+
[a4 l 1]
75+
-- out/value --
76+
== Simplified
77+
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
78+
== Raw
79+
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
80+
== Final
81+
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
82+
== All
83+
{
84+
a0: {
85+
l: ["a", "b"]
86+
}
87+
a1: {
88+
l: ["a", "b"]
89+
}
90+
a2: {
91+
l: _|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
92+
}
93+
a3: {
94+
l: ["a", "b"]
95+
}
96+
a4: {
97+
l: {
98+
@decl(1)
99+
#foo: 1
100+
["a", "b"]
101+
}
102+
}
103+
}
104+
== Eval
105+
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)

0 commit comments

Comments
 (0)