Skip to content

Commit

Permalink
internal/core/export: don't add empty temp struct
Browse files Browse the repository at this point in the history
Fixes bug where a temporary struct was added even if the
underlying value itself was not a struct.

Fixes cue-lang#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]>
  • Loading branch information
mpvl committed Nov 23, 2021
1 parent 75c3d6b commit 0e56b82
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 8 deletions.
15 changes: 7 additions & 8 deletions internal/core/export/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct,
s.Elts = append(s.Elts, st.Elts...)
return s
}
case 2:
if len(e.attrs) > 0 {
break
}
// Simplify.
e.conjuncts = append(e.conjuncts, e.embed...)
return ast.NewBinExpr(token.AND, e.conjuncts...)
}
}

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

e.conjuncts = append(e.conjuncts, s)
switch {
case len(e.conjuncts) == 0:
return s

case len(e.structs) > 0, len(s.Elts) > 0:
e.conjuncts = append(e.conjuncts, s)
}

return ast.NewBinExpr(token.AND, e.conjuncts...)
}
Expand Down
105 changes: 105 additions & 0 deletions internal/core/export/testdata/issue1284.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
-- in.cue --
a0: {
l: ["a",...]
l: ["a","b",...]
}
a1: {
l: [...]
l: ["a",...]
l: ["a","b",...]
}
a2: {
l: [...]
l: ["a",...]
l: ["a","b",...]
l: {}
}
a3: {
l: [...]
l: ["a",...]
l: ["a","b",...]
l: { _ }
}
a4: {
l: [...]
l: ["a",...]
l: ["a","b",...]
l: { _, #foo: 1 }
l: { _, @decl(1) }
}
-- out/definition --
a0: {
l: ["a", ...] & ["a", "b", ...]
}
a1: {
l: [...] & ["a", ...] & ["a", "b", ...]
}
a2: {
l: [...] & ["a", ...] & ["a", "b", ...] & {}
}
a3: {
l: [...] & ["a", ...] & ["a", "b", ...] & {
_
}
}
a4: {
l: [...] & ["a", ...] & ["a", "b", ...] & {
@decl(1)
_
#foo: 1
}
}
-- out/doc --
[]
[a0]
[a0 l]
[a0 l 0]
[a0 l 1]
[a1]
[a1 l]
[a1 l 0]
[a1 l 1]
[a2]
[a2 l]
[a2 l 0]
[a2 l 1]
[a3]
[a3 l]
[a3 l 0]
[a3 l 1]
[a4]
[a4 l]
[a4 l #foo]
[a4 l 0]
[a4 l 1]
-- out/value --
== Simplified
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
== Raw
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
== Final
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
== All
{
a0: {
l: ["a", "b"]
}
a1: {
l: ["a", "b"]
}
a2: {
l: _|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
}
a3: {
l: ["a", "b"]
}
a4: {
l: {
@decl(1)
#foo: 1
["a", "b"]
}
}
}
== Eval
_|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)

0 comments on commit 0e56b82

Please sign in to comment.