Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit 287d43c

Browse files
committed
internal/core/export: don't wrap embedded scalars in _#def
Issue #977 Change-Id: Ic30a8a86096a0d252ebf0ea12f00f3972dfa63de Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9842 Reviewed-by: CUE cueckoo <cueckoo@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
1 parent 1e14710 commit 287d43c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

internal/core/export/export.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ func (p *Profile) Def(r adt.Runtime, pkgID string, v *adt.Vertex) (*ast.File, er
106106

107107
if isDef {
108108
e.inDefinition--
109-
if s, ok := expr.(*ast.StructLit); ok {
109+
if v.Kind() == adt.StructKind {
110110
expr = ast.NewStruct(
111111
ast.Embed(ast.NewIdent("_#def")),
112-
ast.NewIdent("_#def"), s,
112+
ast.NewIdent("_#def"), expr,
113113
)
114114
}
115115
}

internal/core/export/export_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ func TestGenerated(t *testing.T) {
189189
},
190190
out: `_#def, _#def: {c: string}`,
191191
p: export.All,
192+
}, {
193+
// Don't wrap in def if the if the value is an embedded scalar.
194+
// Issue #977
195+
in: func(r *adt.OpContext) (adt.Expr, error) {
196+
v := ctx.CompileString(`
197+
#A: { "foo", #enum: 2 }
198+
`)
199+
v = v.LookupPath(cue.ParsePath("#A"))
200+
201+
_, n := value.ToInternal(v)
202+
return n, nil
203+
},
204+
out: `"foo", #enum: 2`,
205+
p: export.All,
192206
}}
193207
for _, tc := range testCases {
194208
t.Run("", func(t *testing.T) {

0 commit comments

Comments
 (0)