From 784ea0e68660cad6ef94a98a8609467fd0105ffb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:38:57 +0200 Subject: [PATCH] build(deps): bump github.com/Crocmagnon/fatcontext from 0.2.2 to 0.3.0 (#4783) Co-authored-by: Fernandez Ludovic --- go.mod | 2 +- go.sum | 4 +- .../fatcontext/testdata/fatcontext.go | 41 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e6475a882b79..b57c38660459 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/Antonboom/nilnil v0.1.9 github.com/Antonboom/testifylint v1.3.1 github.com/BurntSushi/toml v1.4.0 - github.com/Crocmagnon/fatcontext v0.2.2 + github.com/Crocmagnon/fatcontext v0.3.0 github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 github.com/OpenPeeDeeP/depguard/v2 v2.2.0 diff --git a/go.sum b/go.sum index 3fb6d1ef6f64..4100c3b8140a 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Crocmagnon/fatcontext v0.2.2 h1:OrFlsDdOj9hW/oBEJBNSuH7QWf+E9WPVHw+x52bXVbk= -github.com/Crocmagnon/fatcontext v0.2.2/go.mod h1:WSn/c/+MMNiD8Pri0ahRj0o9jVpeowzavOQplBJw6u0= +github.com/Crocmagnon/fatcontext v0.3.0 h1:S6gNUYNSN9V76Tu017OFgoaOpybmMhwe6Ewh1cYd0jg= +github.com/Crocmagnon/fatcontext v0.3.0/go.mod h1:x3F9YW5CFE7vo+FGA5GzBD1SBXU4FQI0+y1ReG4Q+pY= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 h1:/fTUt5vmbkAcMBt4YQiuC23cV0kEsN1MVMNqeOW43cU= diff --git a/pkg/golinters/fatcontext/testdata/fatcontext.go b/pkg/golinters/fatcontext/testdata/fatcontext.go index f504f4d7ccd7..b2d8bd247657 100644 --- a/pkg/golinters/fatcontext/testdata/fatcontext.go +++ b/pkg/golinters/fatcontext/testdata/fatcontext.go @@ -31,3 +31,44 @@ func example() { func wrapContext(ctx context.Context) context.Context { return context.WithoutCancel(ctx) } + +// storing contexts in a struct isn't recommended, but local copies of a non-pointer struct should act like local copies of a context. +func inStructs(ctx context.Context) { + for i := 0; i < 10; i++ { + c := struct{ Ctx context.Context }{ctx} + c.Ctx = context.WithValue(c.Ctx, "key", i) + c.Ctx = context.WithValue(c.Ctx, "other", "val") + } + + for i := 0; i < 10; i++ { + c := []struct{ Ctx context.Context }{{ctx}} + c[0].Ctx = context.WithValue(c[0].Ctx, "key", i) + c[0].Ctx = context.WithValue(c[0].Ctx, "other", "val") + } + + c := struct{ Ctx context.Context }{ctx} + for i := 0; i < 10; i++ { + c := c + c.Ctx = context.WithValue(c.Ctx, "key", i) + c.Ctx = context.WithValue(c.Ctx, "other", "val") + } + + pc := &struct{ Ctx context.Context }{ctx} + for i := 0; i < 10; i++ { + c := pc + c.Ctx = context.WithValue(c.Ctx, "key", i) // want "nested context in loop" + c.Ctx = context.WithValue(c.Ctx, "other", "val") + } + + r := []struct{ Ctx context.Context }{{ctx}} + for i := 0; i < 10; i++ { + r[0].Ctx = context.WithValue(r[0].Ctx, "key", i) // want "nested context in loop" + r[0].Ctx = context.WithValue(r[0].Ctx, "other", "val") + } + + rp := []*struct{ Ctx context.Context }{{ctx}} + for i := 0; i < 10; i++ { + rp[0].Ctx = context.WithValue(rp[0].Ctx, "key", i) // want "nested context in loop" + rp[0].Ctx = context.WithValue(rp[0].Ctx, "other", "val") + } +}