@@ -16,9 +16,9 @@ func (mt marshalText) MarshalText() ([]byte, error) {
16
16
17
17
var _ encoding.TextMarshaler = marshalText (struct {}{})
18
18
19
- // JSONMarshalSaveTypesWithNoSafe contains a multitude of test cases to marshal different combinations of types to JSON,
20
- // that are save , that is, they will never return an error, if these types are marshaled to JSON.
21
- func JSONMarshalSaveTypesWithNoSafe () {
19
+ // JSONMarshalSafeTypesWithNoSafe contains a multitude of test cases to marshal different combinations of types to JSON,
20
+ // that are safe , that is, they will never return an error, if these types are marshaled to JSON.
21
+ func JSONMarshalSafeTypesWithNoSafe () {
22
22
var err error
23
23
24
24
_ , _ = json .Marshal (nil ) // want "Error return value of `encoding/json.Marshal` is not checked"
@@ -249,37 +249,39 @@ func JSONMarshalSaveTypesWithNoSafe() {
249
249
_ = err
250
250
}
251
251
252
- type structKey struct { id int }
253
- type ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but ommited
254
- F64 float64
255
- F64Ptr * float64
256
- F64Slice []float64
257
- F64Array [10 ]float64
258
- MapStrF64 map [string ]float64
259
- MapEIStr map [interface {}]string
260
- Number json.Number
261
- NumberPtr * json.Number
262
- NumberSlice []json.Number
263
- MapNumberStr map [json.Number ]string
264
- Ei interface {}
265
- Stringer fmt.Stringer
266
- Mt marshalText
267
- MapMarshalTextString map [marshalText ]string
268
-
269
- C128 complex128
270
- C128Ptr * complex128
271
- C128Slice []complex128
272
- C128Array [10 ]complex128
273
- MapBoolStr map [bool ]string
274
- MapF64Str map [float64 ]string
275
- F func ()
276
- Ch chan struct {}
277
- UnsafePtr unsafe.Pointer
278
- MapStructStr map [structKey ]string
279
- }
252
+ type (
253
+ structKey struct { id int }
254
+ ExportedUnsafeAndInvalidStruct struct { // unsafe unexported but omitted
255
+ F64 float64
256
+ F64Ptr * float64
257
+ F64Slice []float64
258
+ F64Array [10 ]float64
259
+ MapStrF64 map [string ]float64
260
+ MapEIStr map [interface {}]string
261
+ Number json.Number
262
+ NumberPtr * json.Number
263
+ NumberSlice []json.Number
264
+ MapNumberStr map [json.Number ]string
265
+ Ei interface {}
266
+ Stringer fmt.Stringer
267
+ Mt marshalText
268
+ MapMarshalTextString map [marshalText ]string
269
+
270
+ C128 complex128
271
+ C128Ptr * complex128
272
+ C128Slice []complex128
273
+ C128Array [10 ]complex128
274
+ MapBoolStr map [bool ]string
275
+ MapF64Str map [float64 ]string
276
+ F func ()
277
+ Ch chan struct {}
278
+ UnsafePtr unsafe.Pointer
279
+ MapStructStr map [structKey ]string
280
+ }
281
+ )
280
282
281
- // JSONMarshalSaveStructWithUnexportedFields contains a struct with unexported, unsafe fields.
282
- func JSONMarshalSaveStructWithUnexportedFieldsWithNoSafe () {
283
+ // JSONMarshalSafeStructWithUnexportedFieldsWithNoSafe contains a struct with unexported, unsafe fields.
284
+ func JSONMarshalSafeStructWithUnexportedFieldsWithNoSafe () {
283
285
var err error
284
286
285
287
var unexportedInStruct struct {
@@ -343,49 +345,49 @@ func JSONMarshalSaveStructWithUnexportedFieldsWithNoSafe() {
343
345
_ = err
344
346
}
345
347
346
- // JSONMarshalSaveStructWithOmittedFields contains a struct with omitted, unsafe fields.
347
- func JSONMarshalSaveStructWithOmittedFieldsWithNoSafe () {
348
+ // JSONMarshalSafeStructWithOmittedFieldsWithNoSafe contains a struct with omitted, unsafe fields.
349
+ func JSONMarshalSafeStructWithOmittedFieldsWithNoSafe () {
348
350
var err error
349
351
350
- var ommitInStruct struct {
352
+ var omitInStruct struct {
351
353
Bool bool // safe exported
352
354
353
- F64 float64 `json:"-"` // unsafe exported but ommited
354
- F64Ptr * float64 `json:"-"` // unsafe exported but ommited
355
- F64Slice []float64 `json:"-"` // unsafe exported but ommited
356
- F64Array [10 ]float64 `json:"-"` // unsafe exported but ommited
357
- MapStrF64 map [string ]float64 `json:"-"` // unsafe exported but ommited
358
- MapEIStr map [interface {}]string `json:"-"` // unsafe exported but ommited
359
- Number json.Number `json:"-"` // unsafe exported but ommited
360
- NumberPtr * json.Number `json:"-"` // unsafe exported but ommited
361
- NumberSlice []json.Number `json:"-"` // unsafe exported but ommited
362
- MapNumberStr map [json.Number ]string `json:"-"` // unsafe exported but ommited
363
- Ei interface {} `json:"-"` // unsafe exported but ommited
364
- Stringer fmt.Stringer `json:"-"` // unsafe exported but ommited
365
- Mt marshalText `json:"-"` // unsafe exported but ommited
366
- MapMarshalTextString map [marshalText ]string `json:"-"` // unsafe exported but ommited
367
- ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
368
- ExportedStructPtr * ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but ommited
369
-
370
- C128 complex128 `json:"-"` // invalid exported but ommited
371
- C128Slice []complex128 `json:"-"` // invalid exported but ommited
372
- C128Array [10 ]complex128 `json:"-"` // invalid exported but ommited
373
- MapBoolStr map [bool ]string `json:"-"` // invalid exported but ommited
374
- MapF64Str map [float64 ]string `json:"-"` // invalid exported but ommited
375
- F func () `json:"-"` // invalid exported but ommited
376
- Ch chan struct {} `json:"-"` // invalid exported but ommited
377
- UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but ommited
378
- MapStructStr map [structKey ]string `json:"-"` // invalid exported but ommited
355
+ F64 float64 `json:"-"` // unsafe exported but omitted
356
+ F64Ptr * float64 `json:"-"` // unsafe exported but omitted
357
+ F64Slice []float64 `json:"-"` // unsafe exported but omitted
358
+ F64Array [10 ]float64 `json:"-"` // unsafe exported but omitted
359
+ MapStrF64 map [string ]float64 `json:"-"` // unsafe exported but omitted
360
+ MapEIStr map [interface {}]string `json:"-"` // unsafe exported but omitted
361
+ Number json.Number `json:"-"` // unsafe exported but omitted
362
+ NumberPtr * json.Number `json:"-"` // unsafe exported but omitted
363
+ NumberSlice []json.Number `json:"-"` // unsafe exported but omitted
364
+ MapNumberStr map [json.Number ]string `json:"-"` // unsafe exported but omitted
365
+ Ei interface {} `json:"-"` // unsafe exported but omitted
366
+ Stringer fmt.Stringer `json:"-"` // unsafe exported but omitted
367
+ Mt marshalText `json:"-"` // unsafe exported but omitted
368
+ MapMarshalTextString map [marshalText ]string `json:"-"` // unsafe exported but omitted
369
+ ExportedStruct ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
370
+ ExportedStructPtr * ExportedUnsafeAndInvalidStruct `json:"-"` // unsafe exported but omitted
371
+
372
+ C128 complex128 `json:"-"` // invalid exported but omitted
373
+ C128Slice []complex128 `json:"-"` // invalid exported but omitted
374
+ C128Array [10 ]complex128 `json:"-"` // invalid exported but omitted
375
+ MapBoolStr map [bool ]string `json:"-"` // invalid exported but omitted
376
+ MapF64Str map [float64 ]string `json:"-"` // invalid exported but omitted
377
+ F func () `json:"-"` // invalid exported but omitted
378
+ Ch chan struct {} `json:"-"` // invalid exported but omitted
379
+ UnsafePtr unsafe.Pointer `json:"-"` // invalid exported but omitted
380
+ MapStructStr map [structKey ]string `json:"-"` // invalid exported but omitted
379
381
}
380
- _ = ommitInStruct .MapStructStr [structKey {1 }]
381
- _ , _ = json .Marshal (ommitInStruct ) // want "Error return value of `encoding/json.Marshal` is not checked"
382
- _ , err = json .Marshal (ommitInStruct ) // struct containing unsafe but omitted, exported fields is safe, but omit-safe is set
382
+ _ = omitInStruct .MapStructStr [structKey {1 }]
383
+ _ , _ = json .Marshal (omitInStruct ) // want "Error return value of `encoding/json.Marshal` is not checked"
384
+ _ , err = json .Marshal (omitInStruct ) // struct containing unsafe but omitted, exported fields is safe, but omit-safe is set
383
385
_ = err
384
386
}
385
387
386
- // JSONMarshalUnsaveTypes contains a multitude of test cases to marshal different combinations of types to JSON,
388
+ // JSONMarshalUnsafeTypes contains a multitude of test cases to marshal different combinations of types to JSON,
387
389
// that can potentially lead to json.Marshal returning an error.
388
- func JSONMarshalUnsaveTypes () {
390
+ func JSONMarshalUnsafeTypes () {
389
391
var err error
390
392
391
393
var f32 float32
@@ -585,7 +587,7 @@ func JSONMarshalInvalidTypes() {
585
587
_ , err = json .Marshal (mapStructStr ) // want "`encoding/json.Marshal` for unsupported type `nosafe.structKey` as map key found"
586
588
_ = err
587
589
588
- var f = func () {}
590
+ f : = func () {}
589
591
_ , _ = json .Marshal (f ) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found"
590
592
_ , err = json .Marshal (f ) // want "`encoding/json.Marshal` for unsupported type `func\\(\\)` found"
591
593
_ = err
0 commit comments