Skip to content

Commit dc11f49

Browse files
authored
Merge pull request #416 from jarredhawkins/issue-415
Ignore unnamed literals in structs
2 parents 03217c3 + 83f7b82 commit dc11f49

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

reflect_extension.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func describeStruct(ctx *ctx, typ reflect2.Type) *StructDescriptor {
341341
if ctx.onlyTaggedField && !hastag && !field.Anonymous() {
342342
continue
343343
}
344-
if tag == "-" {
344+
if tag == "-" || field.Name() == "_" {
345345
continue
346346
}
347347
tagParts := strings.Split(tag, ",")

type_tests/struct_embedded_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func init() {
6060
(*SameLevel2NoTags)(nil),
6161
(*SameLevel2Tagged)(nil),
6262
(*EmbeddedPtr)(nil),
63+
(*UnnamedLiteral)(nil),
6364
)
6465
}
6566

@@ -231,3 +232,7 @@ type EmbeddedPtrOption struct {
231232
type EmbeddedPtr struct {
232233
EmbeddedPtrOption `json:","`
233234
}
235+
236+
type UnnamedLiteral struct {
237+
_ struct{}
238+
}

0 commit comments

Comments
 (0)