File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -50,12 +50,6 @@ type escapingObjectCollector struct {
50
50
func (v * escapingObjectCollector ) Visit (node ast.Node ) (w ast.Visitor ) {
51
51
if id , ok := node .(* ast.Ident ); ok {
52
52
if obj , ok := v .analysis .info .Uses [id ].(* types.Var ); ok {
53
- switch obj .Type ().Underlying ().(type ) {
54
- case * types.Struct , * types.Array :
55
- // always by reference
56
- return nil
57
- }
58
-
59
53
for s := obj .Parent (); s != nil ; s = s .Parent () {
60
54
if s == v .analysis .topScope {
61
55
v .analysis .escaping [obj ] = true
Original file line number Diff line number Diff line change @@ -226,6 +226,23 @@ func TestLoopClosure(t *testing.T) {
226
226
}
227
227
}
228
228
229
+ func TestLoopClosureWithStruct (t * testing.T ) {
230
+ type T struct { A int }
231
+ ts := []T {{0 }, {1 }, {2 }}
232
+ fns := make ([]func () T , 3 )
233
+ for i , t := range ts {
234
+ t := t
235
+ fns [i ] = func () T {
236
+ return t
237
+ }
238
+ }
239
+ for i := range fns {
240
+ if fns [i ]().A != i {
241
+ t .Fail ()
242
+ }
243
+ }
244
+ }
245
+
229
246
func TestNilInterfaceError (t * testing.T ) {
230
247
defer func () {
231
248
if err := recover (); err == nil || ! strings .Contains (err .(error ).Error (), "nil pointer dereference" ) {
You can’t perform that action at this time.
0 commit comments