Can non-nullable references be implemented as a library?
Jonathan M Davis
jmdavisProg at gmx.com
Mon Nov 8 10:07:25 PST 2010
On Sunday, November 07, 2010 18:42:08 Adam Burton wrote:
> 1. Default struct constructor.
> This means the NN can be created without assigning a value. I have tried to
> get around this issue somewhat by adding a null check in the invariant but
> it seems the invariant is not called when using the default constructor.
> Should it be or should it not? If it is then atleast while contracts are
> enabled we get to know about uninitialised NNs.
There are no default constructors for structs. They use init, which is known at
compile-time, so there is no constructor for the invariant to be called after.
It's quite easy to create structs which pass their invariant when you construct
them with a constructor but whose init fails the invariant. The fact that the
invariant gets called before opAssign() doesn't help either:
http://d.puremagic.com/issues/show_bug.cgi?id=5058
The result is that at this point, you pretty much either need to have init pass
your invariant or have no invariant.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list