Skip to content

SA1026: false positive for fields in embedded struct that are overridden #1712

@arp242

Description

@arp242

The following code:

func main() {
    resp := &http.Response{
        StatusCode: 200,
        // ... etc
    }

    j, err := json.Marshal(struct {
        *http.Response
        Body    []byte
        Request *http.Request
    }{Response: resp, Body: []byte("ABC")})

    if err != nil {
        panic(err)
    }

    fmt.Println(string(j))
}

Works as expected; the http.Request struct contains some fields that can't be marshaled (func, channel), but it overrides the Request field:

% go run test.go
{
   [..]
   "StatusCode": 200,
   [..]
}

But staticcheck errors:

% staticcheck test.go
test.go:15:25: trying to marshal unsupported type func() (io.ReadCloser, error), via x.Request.GetBody (SA1026)

staticcheck (devel, v0.7.0-0.dev.0.20260409232628-ba2c20843b32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions