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

Commit

Permalink
internal/core/export: don't wrap embedded scalars in _#def
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed May 19, 2021
1 parent 1e14710 commit 287d43c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/core/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ func (p *Profile) Def(r adt.Runtime, pkgID string, v *adt.Vertex) (*ast.File, er

if isDef {
e.inDefinition--
if s, ok := expr.(*ast.StructLit); ok {
if v.Kind() == adt.StructKind {
expr = ast.NewStruct(
ast.Embed(ast.NewIdent("_#def")),
ast.NewIdent("_#def"), s,
ast.NewIdent("_#def"), expr,
)
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/core/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ func TestGenerated(t *testing.T) {
},
out: `_#def, _#def: {c: string}`,
p: export.All,
}, {
// Don't wrap in def if the if the value is an embedded scalar.
// Issue #977
in: func(r *adt.OpContext) (adt.Expr, error) {
v := ctx.CompileString(`
#A: { "foo", #enum: 2 }
`)
v = v.LookupPath(cue.ParsePath("#A"))

_, n := value.ToInternal(v)
return n, nil
},
out: `"foo", #enum: 2`,
p: export.All,
}}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
Expand Down

0 comments on commit 287d43c

Please sign in to comment.