Skip to content

Commit 4cda4a3

Browse files
committed
cmd/cue/cmd: allow inlined embedding of pointer types
Fixes #554 Change-Id: I8c64db86ce83cd4a6cd2c24c0701fead545e8e7b Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7381 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 99d18dc commit 4cda4a3

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

cmd/cue/cmd/get_go.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,13 @@ func (e *extractor) addFields(x *types.Struct, st *cueast.StructLit) {
10691069
}
10701070
if f.Anonymous() && e.isInline(x.Tag(i)) {
10711071
typ := f.Type()
1072+
for {
1073+
p, ok := typ.(*types.Pointer)
1074+
if !ok {
1075+
break
1076+
}
1077+
typ = p.Elem()
1078+
}
10721079
if _, ok := typ.(*types.Named); ok {
10731080
embed := &cueast.EmbedDecl{Expr: e.makeType(typ)}
10741081
if i > 0 {

cmd/cue/cmd/testdata/code/go/pkg2/pkg2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ type Barzer struct {
3535
XY bool `json:"x-y"`
3636

3737
Err error
38+
39+
*Inline `json:",inline"`
3840
}
3941

4042
const Perm = 0755
4143

4244
const Few = 3
4345

4446
const Couple int = 2
47+
48+
type Inline struct{ A int }

cmd/cue/cmd/testdata/pkg/cuelang.org/go/cmd/cue/cmd/testdata/code/go/pkg2/pkg2_go_gen.cue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ import t "time"
1818
S: string
1919
"x-y": bool @go(XY)
2020
Err: _ @go(,error)
21+
22+
#Inline
2123
}
2224

2325
#Perm: 0o755
2426

2527
#Few: 3
2628

2729
#Couple: int & 2
30+
31+
#Inline: A: int

0 commit comments

Comments
 (0)