Skip to content

Commit

Permalink
fixed generation for alias ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorolyov committed Mar 23, 2021
1 parent 0cfd086 commit 697a73d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions field_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (g *fieldGenerator) writePointerDef(ctx fieldGenContext) {
case astparser.TypeSimple:
g.writeSimpleDef(ctx.withFieldName("*"+ctx.fieldName))
case astparser.TypeCustom:
if tt.AliasType != nil {
ctx = ctx.withFieldName("*"+ctx.fieldName)
}
g.writeCustomDef(ctx)
default:
panic(fmt.Sprintf("unsupported array pointer innter type %T field name %s", tt, ctx.fieldName))
Expand Down
1 change: 1 addition & 0 deletions fixtures_test/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Dep struct {
ConstInt ConstInt
ConstStrArray []ConstStr
ConstStrMap map[string]ConstStr
ConstStrPtr *ConstStr
}

type Optional struct {
Expand Down
4 changes: 4 additions & 0 deletions fixtures_test/custom.zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (m *Dep) MarshalLogObject(enc zapcore.ObjectEncoder) error {
return nil
}))

keyName = "ConstStrPtr"
if m.ConstStrPtr != nil {
enc.AddString(keyName, string(*m.ConstStrPtr))
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("backoff", func() {
It("should generate golden files", func() {
cfg := astparser.Config{
InputDir: "fixtures_test",
IncludeRegexp: "primitives.go|custom.go",
IncludeRegexp: "custom.go",
}
sources, err := astparser.Load(cfg)
Ω(err).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit 697a73d

Please sign in to comment.