Skip to content

Commit f0f62b8

Browse files
committed
cue/ast: allow use of Embed in NewStruct
Eventually &ast.EmbedDecl may go. Using Embed allows for a smooth transition, rather than supporting EmbedDecl directly. It is also more convenient. Change-Id: Iec869ff00bf7e11acbce3ed07a41a6fee2934423 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6562 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent c615c91 commit f0f62b8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cue/ast/ast.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ func NewStruct(fields ...interface{}) *StructLit {
520520
case *LetClause:
521521
s.Elts = append(s.Elts, x)
522522
continue
523+
case *embedding:
524+
s.Elts = append(s.Elts, (*EmbedDecl)(x))
525+
continue
523526
case Label:
524527
label = x
525528
case string:
@@ -561,6 +564,13 @@ func NewStruct(fields ...interface{}) *StructLit {
561564
return s
562565
}
563566

567+
// Embed can be used in conjunction with NewStruct to embed values.
568+
func Embed(x Expr) *embedding {
569+
return (*embedding)(&EmbedDecl{Expr: x})
570+
}
571+
572+
type embedding EmbedDecl
573+
564574
// A ListLit node represents a literal list.
565575
type ListLit struct {
566576
Lbrack token.Pos // position of "["

cue/ast/astutil/sanitize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (z *sanitizer) unshadow(parent ast.Node, base string, link ast.Node) string
136136
case *ast.StructLit:
137137
decls = &x.Elts
138138
default:
139-
panic("impossible scope")
139+
panic(fmt.Sprintf("impossible scope type %T", parent))
140140
}
141141

142142
i := 0

0 commit comments

Comments
 (0)