| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package a |
| 14 |
|
| 15 |
import "sync" |
| 16 |
|
| 17 |
func OkFunc(*sync.Mutex) {} |
| 18 |
func BadFunc(sync.Mutex) {} |
| 19 |
func BadFunc2(sync.Map) {} |
| 20 |
func OkRet() *sync.Mutex {} |
| 21 |
func BadRet() sync.Mutex {} |
| 22 |
|
| 23 |
var ( |
| 24 |
OkClosure = func(*sync.Mutex) {} |
| 25 |
BadClosure = func(sync.Mutex) {} |
| 26 |
BadClosure2 = func(sync.Map) {} |
| 27 |
) |
| 28 |
|
| 29 |
type EmbeddedRWMutex struct { |
| 30 |
sync.RWMutex |
| 31 |
} |
| 32 |
|
| 33 |
func (*EmbeddedRWMutex) OkMeth() {} |
| 34 |
func (EmbeddedRWMutex) BadMeth() {} |
| 35 |
func OkFunc(e *EmbeddedRWMutex) {} |
| 36 |
func BadFunc(EmbeddedRWMutex) {} |
| 37 |
func OkRet() *EmbeddedRWMutex {} |
| 38 |
func BadRet() EmbeddedRWMutex {} |
| 39 |
|
| 40 |
type FieldMutex struct { |
| 41 |
s sync.Mutex |
| 42 |
} |
| 43 |
|
| 44 |
func (*FieldMutex) OkMeth() {} |
| 45 |
func (FieldMutex) BadMeth() {} |
| 46 |
func OkFunc(*FieldMutex) {} |
| 47 |
func BadFunc(FieldMutex, int) {} |
| 48 |
|
| 49 |
type L0 struct { |
| 50 |
L1 |
| 51 |
} |
| 52 |
|
| 53 |
type L1 struct { |
| 54 |
l L2 |
| 55 |
} |
| 56 |
|
| 57 |
type L2 struct { |
| 58 |
sync.Mutex |
| 59 |
} |
| 60 |
|
| 61 |
func (*L0) Ok() {} |
| 62 |
func (L0) Bad() {} |
| 63 |
|
| 64 |
type EmbeddedMutexPointer struct { |
| 65 |
s *sync.Mutex |
| 66 |
} |
| 67 |
|
| 68 |
func (*EmbeddedMutexPointer) Ok() {} |
| 69 |
func (EmbeddedMutexPointer) AlsoOk() {} |
| 70 |
func StillOk(EmbeddedMutexPointer) {} |
| 71 |
func LookinGood() EmbeddedMutexPointer {} |
| 72 |
|
| 73 |
type EmbeddedLocker struct { |
| 74 |
sync.Locker |
| 75 |
} |
| 76 |
|
| 77 |
func (*EmbeddedLocker) Ok() {} |
| 78 |
func (EmbeddedLocker) AlsoOk() {} |
| 79 |
|
| 80 |
type CustomLock struct{} |
| 81 |
|
| 82 |
func (*CustomLock) Lock() {} |
| 83 |
func (*CustomLock) Unlock() {} |
| 84 |
|
| 85 |
func Ok(*CustomLock) {} |
| 86 |
func Bad(CustomLock) {} |
| 87 |
|
| 88 |
|
| 89 |
func FuncCallInterfaceArg(f func(a int, b interface{})) { |
| 90 |
var m sync.Mutex |
| 91 |
var t struct{ lock sync.Mutex } |
| 92 |
|
| 93 |
f(1, "foo") |
| 94 |
f(2, &t) |
| 95 |
f(3, &sync.Mutex{}) |
| 96 |
f(4, m) |
| 97 |
f(5, t) |
| 98 |
var fntab []func(t) |
| 99 |
fntab[0](t) |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
func ReturnViaInterface(x int) (int, interface{}) { |
| 104 |
var m sync.Mutex |
| 105 |
var t struct{ lock sync.Mutex } |
| 106 |
|
| 107 |
switch x % 4 { |
| 108 |
case 0: |
| 109 |
return 0, "qwe" |
| 110 |
case 1: |
| 111 |
return 1, &sync.Mutex{} |
| 112 |
case 2: |
| 113 |
return 2, m |
| 114 |
default: |
| 115 |
return 3, t |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
func AcceptedCases() { |
| 122 |
x := EmbeddedRwMutex{} |
| 123 |
x = BadRet() |
| 124 |
x = *OKRet() |
| 125 |
} |