@@ -393,6 +393,7 @@ func JSONMarshalUnsafeTypes() {
393
393
var err error
394
394
395
395
var f32 float32
396
+ json .Marshal (f32 ) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
396
397
_ , _ = json .Marshal (f32 ) // ERROR "Error return value of `encoding/json.Marshal` is not checked: unsafe type `float32` found"
397
398
_ , err = json .Marshal (f32 ) // err is checked
398
399
_ = err
@@ -516,6 +517,7 @@ func JSONMarshalInvalidTypes() {
516
517
var err error
517
518
518
519
var c64 complex64
520
+ json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
519
521
_ , _ = json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
520
522
_ , err = json .Marshal (c64 ) // ERROR "`encoding/json.Marshal` for unsupported type `complex64` found"
521
523
_ = err
@@ -612,3 +614,28 @@ func NotJSONMarshal() {
612
614
f := func () bool { return false }
613
615
_ = f ()
614
616
}
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