Re: [go-nuts] Panic getting swallowed by defer in Go 1.11
NB I’m unable to reproduce this bug without the pointer indirection. On Tuesday, September 4, 2018 at 3:38:35 AM UTC+10, Sam Whited wrote: > > On Mon, Sep 3, 2018, at 04:10, ama...@naucera.net wrote: > > type S []int > > > > func (s *S) Last() int { > > return (*s)[len(*s) - 1] > > } > > On an unrelated matter, the extra indirection is (probably) not what you > want here, slices are already a pointer type. For more information see > https://blog.golang.org/go-slices-usage-and-internals. > > That is to say, the following works in more or less the same way (and is > much easier to read): > > func (s S) Last() int { > return s[len(s)-1] > } > > Apologies if this is something you're already aware of; for future > generations finding this thread I wanted to mention it. > > —Sam > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Panic getting swallowed by defer in Go 1.11
NB I']m On Tuesday, September 4, 2018 at 3:38:35 AM UTC+10, Sam Whited wrote: > > On Mon, Sep 3, 2018, at 04:10, ama...@naucera.net wrote: > > type S []int > > > > func (s *S) Last() int { > > return (*s)[len(*s) - 1] > > } > > On an unrelated matter, the extra indirection is (probably) not what you > want here, slices are already a pointer type. For more information see > https://blog.golang.org/go-slices-usage-and-internals. > > That is to say, the following works in more or less the same way (and is > much easier to read): > > func (s S) Last() int { > return s[len(s)-1] > } > > Apologies if this is something you're already aware of; for future > generations finding this thread I wanted to mention it. > > —Sam > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Panic getting swallowed by defer in Go 1.11
Thanks, that looks like what I’m seeing (I’m able to coax it to produce a pointer which segfaults the runtime). On Tuesday, September 4, 2018 at 3:34:43 AM UTC+10, Paul Jolly wrote: > > I suspect that you've just run into some variation on > https://github.com/golang/go/issues/27378 > > Giovanni/Daniel/others better placed might be able to confirm more > precisely however. > > > On Mon, 3 Sep 2018 at 17:49, > wrote: > > > > Hi all, > > > > Since Go 1.11, the following test seems to pass when I would expect it > to panic with index out of range: > > > > package weirdness > > > > import "testing" > > > > > > type S []int > > > > func (s *S) Last() int { > > return (*s)[len(*s) - 1] > > } > > > > > > func TestWeirdness(t *testing.T) { > > var s S > > > > defer func() {}() > > > > s.Last() > > } > > > > Strangely, if the declaration of the s variable is moved below the > defer, it panics as expected. Any idea what’s going on? > > > > -- > > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to golang-nuts...@googlegroups.com . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Panic getting swallowed by defer in Go 1.11
On Mon, Sep 3, 2018, at 04:10, ama...@naucera.net wrote: > type S []int > > func (s *S) Last() int { > return (*s)[len(*s) - 1] > } On an unrelated matter, the extra indirection is (probably) not what you want here, slices are already a pointer type. For more information see https://blog.golang.org/go-slices-usage-and-internals. That is to say, the following works in more or less the same way (and is much easier to read): func (s S) Last() int { return s[len(s)-1] } Apologies if this is something you're already aware of; for future generations finding this thread I wanted to mention it. —Sam -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Panic getting swallowed by defer in Go 1.11
I suspect that you've just run into some variation on https://github.com/golang/go/issues/27378 Giovanni/Daniel/others better placed might be able to confirm more precisely however. On Mon, 3 Sep 2018 at 17:49, wrote: > > Hi all, > > Since Go 1.11, the following test seems to pass when I would expect it to > panic with index out of range: > > package weirdness > > import "testing" > > > type S []int > > func (s *S) Last() int { > return (*s)[len(*s) - 1] > } > > > func TestWeirdness(t *testing.T) { > var s S > > defer func() {}() > > s.Last() > } > > Strangely, if the declaration of the s variable is moved below the defer, it > panics as expected. Any idea what’s going on? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.