Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-17 Thread tchaloupka via Digitalmars-d-learn
On Friday, 16 October 2020 at 16:00:07 UTC, Steven Schveighoffer wrote: On 10/16/20 9:12 AM, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior expected?

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/20 9:05 AM, Steven Schveighoffer wrote: > The destruction of members is outside the destructor's purview. It can't > turn the destruction off, so it should logically be considered part of > an enclosing function. Thank you. Makes sense. Ali

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/16/20 11:11 AM, Ali Çehreli wrote: On 10/16/20 6:12 AM, tchaloupka wrote: > struct Foo { >  Bar bar; >  bool err; > >  ~this() { >  // scope(failure) destroy(bar); // < this fixes the Bar > destructor call >  enforce(!err, "Test err"); Well, that check

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/16/20 9:12 AM, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior expected? I would say it's a bug. The compiler is going to call the member

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 16 October 2020 at 15:19:51 UTC, Paul Backus wrote: On Friday, 16 October 2020 at 13:12:04 UTC, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Paul Backus via Digitalmars-d-learn
On Friday, 16 October 2020 at 13:12:04 UTC, tchaloupka wrote: So when the exception is thrown within Foo destructor (and it's bad on it's own but can easily happen as destructors aren't nothrow @nogc by default). Is this behavior expected? This is a compiler/language bug. It was fixed in

Re: Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/20 6:12 AM, tchaloupka wrote: > struct Foo { > Bar bar; > bool err; > > ~this() { > // scope(failure) destroy(bar); // < this fixes the Bar > destructor call > enforce(!err, "Test err"); Well, that check means "cannot continue", which means the compiler

Struct field destructor not called when exception is thrown in the main struct destructor

2020-10-16 Thread tchaloupka via Digitalmars-d-learn
Found a pretty nasty bug in vibe-d: https://github.com/vibe-d/vibe.d/issues/2484 And it's caused by this behavior. ```D import std; struct Foo { Bar bar; bool err; ~this() { // scope(failure) destroy(bar); // < this fixes the Bar destructor call enforce(!err,