diff --git a/musttag.go b/musttag.go index c4f4f7d..7be684f 100644 --- a/musttag.go +++ b/musttag.go @@ -222,7 +222,7 @@ func (c *checker) checkStruct(styp *types.Struct, tag string) (valid bool) { // Do not recurse into ignored fields. if tagValue == "-" { - return true + continue } if valid := c.checkType(field.Type(), tag); !valid { diff --git a/testdata/src/tests/tests.go b/testdata/src/tests/tests.go index 7bcc489..25461a1 100644 --- a/testdata/src/tests/tests.go +++ b/testdata/src/tests/tests.go @@ -165,6 +165,22 @@ func ignoredNestedType() { json.Marshal(&Foo{}) // no error } +func ignoredNestedTypeWithSubsequentNoTagField() { + type Nested struct { + NoTag string + } + type Foo struct { + Ignored Nested `json:"-"` + Exported string `json:"exported"` + NoTag string + } + var foo Foo + json.Marshal(foo) // want "the given struct should be annotated with the `json` tag" + json.Marshal(&foo) // want "the given struct should be annotated with the `json` tag" + json.Marshal(Foo{}) // want "the given struct should be annotated with the `json` tag" + json.Marshal(&Foo{}) // want "the given struct should be annotated with the `json` tag" +} + func interfaceSliceType() { type WithMarshallableSlice struct { List []Marshaler `json:"marshallable"`