| 1 | // This test relies on a compiler bug patched in Go 1.26. |
| 2 | //go:build !go1.26 |
| 3 | |
| 4 | package a |
| 5 | |
| 6 | import "sync" |
| 7 | |
| 8 | // These examples are taken from golang/go#61678, modified so that A and B |
| 9 | // contain a mutex. |
| 10 | |
| 11 | type A struct { |
| 12 | a A |
| 13 | mu sync.Mutex |
| 14 | } |
| 15 | |
| 16 | type B struct { |
| 17 | a A |
| 18 | b B |
| 19 | mu sync.Mutex |
| 20 | } |
| 21 | |
| 22 | func okay(x A) {} |
| 23 | func sure() { var x A; nop(x) } |
| 24 | |
| 25 | var fine B |
| 26 | |
| 27 | func what(x B) {} // want `passes lock by value` |
| 28 | func bad() { var x B; nop(x) } // want `copies lock value` |
| 29 | func good() { nop(B{}) } |
| 30 | func stillgood() { nop(B{b: B{b: B{b: B{}}}}) } |
| 31 | func nope() { nop(B{}.b) } // want `copies lock value` |
| 32 | |
| 33 | func nop(any) {} // only used to get around unused variable errors |