this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+16 -2
+2 -2
internal/core/export/export.go
··· 106 106 107 107 if isDef { 108 108 e.inDefinition-- 109 - if s, ok := expr.(*ast.StructLit); ok { 109 + if v.Kind() == adt.StructKind { 110 110 expr = ast.NewStruct( 111 111 ast.Embed(ast.NewIdent("_#def")), 112 - ast.NewIdent("_#def"), s, 112 + ast.NewIdent("_#def"), expr, 113 113 ) 114 114 } 115 115 }
+14
internal/core/export/export_test.go
··· 189 189 }, 190 190 out: `_#def, _#def: {c: string}`, 191 191 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, 192 206 }} 193 207 for _, tc := range testCases { 194 208 t.Run("", func(t *testing.T) {