From e92a5990c578ffe35b450f645bb847bb843d2941 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 14:07:33 +0000 Subject: [PATCH 1/2] build(deps): bump github.com/Crocmagnon/fatcontext from 0.2.2 to 0.3.0 Bumps [github.com/Crocmagnon/fatcontext](https://github.com/Crocmagnon/fatcontext) from 0.2.2 to 0.3.0. - [Release notes](https://github.com/Crocmagnon/fatcontext/releases) - [Changelog](https://github.com/Crocmagnon/fatcontext/blob/master/.goreleaser.yaml) - [Commits](https://github.com/Crocmagnon/fatcontext/compare/v0.2.2...v0.3.0) --- updated-dependencies: - dependency-name: github.com/Crocmagnon/fatcontext dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ae80d08e8379..c7315be93133 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.2.0 github.com/OpenPeeDeeP/depguard/v2 v2.2.0 diff --git a/go.sum b/go.sum index 96fe04f12b6e..e8ace026b501 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.2.0 h1:sATXp1x6/axKxz2Gjxv8MALP0bXaNRfQinEwyfMcx8c= From ea381f0b4afb725f02b3f4860386d0f847dd8207 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 1 Jun 2024 16:10:33 +0200 Subject: [PATCH 2/2] chore: update tests --- .../fatcontext/testdata/fatcontext.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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") + } +}