[Issue 1228] Class invariants should not be called before the object is fully constructed

Ary Manzana ary at esperanto.org.ar
Fri May 11 13:05:56 PDT 2007


d-bugmail at puremagic.com escribió:
> http://d.puremagic.com/issues/show_bug.cgi?id=1228
> 
> 
> 
> 
> 
> ------- Comment #1 from braddr at puremagic.com  2007-05-11 14:25 -------
> Invariants are checked after every public member function's execution as well,
> so the behavior you're seeing at least meets the spec.  Now, I can see some
> arguments for not having invariants checked until construction is complete, but
> that'd be a change in documented behavior.
> 
> 

Sound reasonable to me, too. You can always refactor to:

class foo {

         this() {
                 Stdout("entering constructor").newline;
                 barInternal();
                 Stdout("leaving constructor").newline;
         }

         void bar() {
                 barInternal();
         }

	private void barInternal() {
		Stdout("method bar()").newline;
	}

         invariant {
                 Stdout("invariant").newline;
         }
}


More information about the Digitalmars-d-bugs mailing list