Compiler error on struct with invariant and postblitz

Jonathan M Davis jmdavisProg at
Sat Jan 1 12:56:20 PST 2011

On Saturday 01 January 2011 11:17:36 Alex Khmara wrote:
> Please help: is it compiler bug or I'm doing something wrong?
> This code:
> module properties;
> struct PropertyList {
> <-->invariant() {
> <--><-->assert(1);
> <-->}
> <-->this(this) {
> <--><-->_props = [];
> <-->}
> <-->string[] _props;
> }
> gives compiler error:
> Error: __result = this is not mutable
> Error: __result = this is not an lvalue
> Without invariant all works good.

It's hard to read what you're doing when have those extra arrows in there.

In any case, create a bug report for it. There are several bugs at present with 
invariants not working because of things like a public member function being 
pure (that one you can fix by marking the invariant as pure) or returning a ref. 
My guess would be that the problem relates to bug which makes it so that 
postblit constructors cannot currently copy const or immutable objects, but I 
don't know, since problems with __result have to do with the return value of a 
function (which would be the result of postblit rather than what's passed in). 
So, just create a bug report on it and it can be sorted out with the other 
invariant, postblit, and const problems. For the moment, it probably means that 
you can't have both an invariant and a postblit constructor, which sucks, but 
until the bug is fixed, I don't see what else you can do.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list