diff --git a/staticcheck/fakexml/marshal.go b/staticcheck/fakexml/marshal.go index 9c71e863..97077c59 100644 --- a/staticcheck/fakexml/marshal.go +++ b/staticcheck/fakexml/marshal.go @@ -289,7 +289,19 @@ func (e *Encoder) marshalAttr(start *StartElement, name Name, val fakereflect.Ty func (e *Encoder) marshalSimple(val fakereflect.TypeAndCanAddr, stack string) error { switch val.Type.Underlying().(type) { - case *types.Basic, *types.Interface: + case *types.Basic: + basic := val.Type.Underlying().(*types.Basic) + switch basic.Kind() { + case types.Bool, + types.Int, types.Int8, types.Int16, types.Int32, types.Int64, + types.Uint, types.Uint8, types.Uint16, types.Uint32, types.Uint64, types.Uintptr, + types.Float32, types.Float64, types.String, + types.UntypedBool, types.UntypedInt, types.UntypedRune, types.UntypedFloat, types.UntypedString, types.UntypedNil: + return nil + default: + return &UnsupportedTypeError{val.Type, stack} + } + case *types.Interface: return nil case *types.Slice, *types.Array: basic, ok := val.Elem().Type.Underlying().(*types.Basic) diff --git a/staticcheck/sa1026/testdata/go1.0/CheckUnsupportedMarshal/CheckUnsupportedMarshal.go b/staticcheck/sa1026/testdata/go1.0/CheckUnsupportedMarshal/CheckUnsupportedMarshal.go index 2ae94692..40fb0b80 100644 --- a/staticcheck/sa1026/testdata/go1.0/CheckUnsupportedMarshal/CheckUnsupportedMarshal.go +++ b/staticcheck/sa1026/testdata/go1.0/CheckUnsupportedMarshal/CheckUnsupportedMarshal.go @@ -4,6 +4,7 @@ import ( "encoding/json" "encoding/xml" "time" + "unsafe" ) type T1 struct { @@ -281,6 +282,13 @@ func otherPackageXML() { xml.Marshal(x) //@ diag(`unsupported type <-chan time.Time, via x.C`) } +func unsupportedXMLBasicTypes() { + var c complex128 + var p unsafe.Pointer + xml.Marshal(c) //@ diag(`unsupported type complex128`) + xml.Marshal(p) //@ diag(`unsupported type unsafe.Pointer`) +} + type ToplevelPointerMarshalerXML struct { Field map[string]string }