Skip to content

Commit

Permalink
cue: Keep Vertex if returned from conversion of Go to CUE
Browse files Browse the repository at this point in the history
By keeping the Vertex, we maintain the vertex's internal state, such as
its Structs fields, which is essential for being able to correct sort
fields for output.

Signed-off-by: Matthew Sackman <[email protected]>
Change-Id: Ie9faa925dce7fc5bb1fb2a4f68b239b751763308
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202451
Reviewed-by: Marcel van Lohuizen <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
cuematthew committed Nov 5, 2024
1 parent c374e6c commit dbef7c5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cue/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,13 @@ func (c *Context) Encode(x interface{}, option ...EncodeOption) Value {
ctx := c.ctx()
// TODO: is true the right default?
expr := convert.GoValueToValue(ctx, x, options.nilIsTop)
n := &adt.Vertex{}
n.AddConjunct(adt.MakeRootConjunct(nil, expr))
var n *adt.Vertex
if v, ok := expr.(*adt.Vertex); ok {
n = v
} else {
n = &adt.Vertex{}
n.AddConjunct(adt.MakeRootConjunct(nil, expr))
}
n.Finalize(ctx)
return c.make(n)
}
Expand All @@ -390,8 +395,13 @@ func (c *Context) EncodeType(x interface{}, option ...EncodeOption) Value {
if err != nil {
return c.makeError(err)
}
n := &adt.Vertex{}
n.AddConjunct(adt.MakeRootConjunct(nil, expr))
var n *adt.Vertex
if v, ok := expr.(*adt.Vertex); ok {
n = v
} else {
n = &adt.Vertex{}
n.AddConjunct(adt.MakeRootConjunct(nil, expr))
}
n.Finalize(ctx)
return c.make(n)
}
Expand Down

0 comments on commit dbef7c5

Please sign in to comment.