Skip to content

Commit 784ea0e

Browse files
build(deps): bump github.com/Crocmagnon/fatcontext from 0.2.2 to 0.3.0 (#4783)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent eb23eaf commit 784ea0e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/Antonboom/nilnil v0.1.9
1212
github.com/Antonboom/testifylint v1.3.1
1313
github.com/BurntSushi/toml v1.4.0
14-
github.com/Crocmagnon/fatcontext v0.2.2
14+
github.com/Crocmagnon/fatcontext v0.3.0
1515
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
1616
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0
1717
github.com/OpenPeeDeeP/depguard/v2 v2.2.0

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/fatcontext/testdata/fatcontext.go

+41
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,44 @@ func example() {
3131
func wrapContext(ctx context.Context) context.Context {
3232
return context.WithoutCancel(ctx)
3333
}
34+
35+
// storing contexts in a struct isn't recommended, but local copies of a non-pointer struct should act like local copies of a context.
36+
func inStructs(ctx context.Context) {
37+
for i := 0; i < 10; i++ {
38+
c := struct{ Ctx context.Context }{ctx}
39+
c.Ctx = context.WithValue(c.Ctx, "key", i)
40+
c.Ctx = context.WithValue(c.Ctx, "other", "val")
41+
}
42+
43+
for i := 0; i < 10; i++ {
44+
c := []struct{ Ctx context.Context }{{ctx}}
45+
c[0].Ctx = context.WithValue(c[0].Ctx, "key", i)
46+
c[0].Ctx = context.WithValue(c[0].Ctx, "other", "val")
47+
}
48+
49+
c := struct{ Ctx context.Context }{ctx}
50+
for i := 0; i < 10; i++ {
51+
c := c
52+
c.Ctx = context.WithValue(c.Ctx, "key", i)
53+
c.Ctx = context.WithValue(c.Ctx, "other", "val")
54+
}
55+
56+
pc := &struct{ Ctx context.Context }{ctx}
57+
for i := 0; i < 10; i++ {
58+
c := pc
59+
c.Ctx = context.WithValue(c.Ctx, "key", i) // want "nested context in loop"
60+
c.Ctx = context.WithValue(c.Ctx, "other", "val")
61+
}
62+
63+
r := []struct{ Ctx context.Context }{{ctx}}
64+
for i := 0; i < 10; i++ {
65+
r[0].Ctx = context.WithValue(r[0].Ctx, "key", i) // want "nested context in loop"
66+
r[0].Ctx = context.WithValue(r[0].Ctx, "other", "val")
67+
}
68+
69+
rp := []*struct{ Ctx context.Context }{{ctx}}
70+
for i := 0; i < 10; i++ {
71+
rp[0].Ctx = context.WithValue(rp[0].Ctx, "key", i) // want "nested context in loop"
72+
rp[0].Ctx = context.WithValue(rp[0].Ctx, "other", "val")
73+
}
74+
}

0 commit comments

Comments
 (0)