@@ -393,6 +393,7 @@ func JSONMarshalUnsafeTypes() {
393393 var err error
394394
395395 var f32 float32
396+ json .Marshal (f32 ) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
396397 _ , _ = json .Marshal (f32 ) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
397398 _ , err = json .Marshal (f32 ) // err is checked
398399 _ = err
@@ -516,6 +517,7 @@ func JSONMarshalInvalidTypes() {
516517 var err error
517518
518519 var c64 complex64
520+ json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
519521 _ , _ = json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
520522 _ , err = json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
521523 _ = err
@@ -612,3 +614,28 @@ func NotJSONMarshal() {
612614 f := func () bool { return false }
613615 _ = f ()
614616}
617+
618+ // JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
619+ func JSONMarshalStructWithoutExportedFields () {
620+ var err error
621+
622+ var withoutExportedFields struct {
623+ privateField bool
624+ ExportedButOmittedField bool `json:"-"`
625+ }
626+ _ , err = json .Marshal (withoutExportedFields ) // want "Error argument passed to `encoding/json.Marshal` does not contain any exported field"
627+ _ = err
628+ }
629+
630+ // JSONMarshalStructWithoutExportedFields contains a struct without exported fields.
631+ func JSONMarshalStructWithNestedStructWithoutExportedFields () {
632+ var err error
633+
634+ var withNestedStructWithoutExportedFields struct {
635+ ExportedStruct struct {
636+ privatField bool
637+ }
638+ }
639+ _ , err = json .Marshal (withNestedStructWithoutExportedFields )
640+ _ = err
641+ }
0 commit comments