Re: [go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-14 Thread 'Spencer Nelson' via golang-nuts
Yes, very tricky stuff. I've replied on the issue - it seems best to keep discussion in one place. Thank you very much for opening the issue! On Mon, Aug 14, 2017 at 2:35 PM, Ian Lance Taylor wrote: > On Fri, Aug 11, 2017 at 4:38 PM, Ian Lance Taylor wrote: > > On Thu, Aug 10, 2017 at 1:43 PM,

Re: [go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-14 Thread Ian Lance Taylor
On Fri, Aug 11, 2017 at 4:38 PM, Ian Lance Taylor wrote: > On Thu, Aug 10, 2017 at 1:43 PM, wrote: >> >> Yes, it makes sense that it would be impossible to really check at that >> level. What surprised me was that this does not trigger vet: >> >> for i := range slice { >> go f(i) >> _ =

Re: [go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-11 Thread Ian Lance Taylor
On Thu, Aug 10, 2017 at 1:43 PM, wrote: > > Yes, it makes sense that it would be impossible to really check at that > level. What surprised me was that this does not trigger vet: > > for i := range slice { > go f(i) > _ = 1 > } > > Yet this does trigger vet: > > for i := range slice { >

Re: [go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-10 Thread spencer
Yes, it makes sense that it would be impossible to really check at that level. What surprised me was that this does not trigger vet: for i := range slice { go f(i) _ = 1 } Yet this does trigger vet: for i := range slice { _ = 1 go f(i) } Is there something special about the las

Re: [go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-10 Thread Steven Blenkinsop
If you have a loop like: for i := range slice { f(&i) } There's no way to know whether f launches a goroutine that captures the loop variable without also evaluating the body of f and potentially every function directly or indirectly called by f. If i escapes into a global variable, you also

[go-nuts] Why does vet's 'rangeloop' check only check the last statement of a loop?

2017-08-10 Thread spencer
I've noticed that cmd/vet's rangeloop check, which warns you about binding to range loop variables in function literals which are launched with 'go' or 'defer', is more limited than I thought: https://github.com/golang/go/blob/d5ad7793d610bddfb3e7e09b8dafa0b0837f0cb2/src/cmd/vet/rangeloop.go#L6-