Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 01, 2011 Compiler error on struct with invariant and postblitz | ||||
---|---|---|---|---|
| ||||
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. |
January 01, 2011 Re: Compiler error on struct with invariant and postblitz | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Khmara | I forgot to mention - it's dmd 2.051 |
January 01, 2011 Re: Compiler error on struct with invariant and postblitz | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Khmara | 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 http://d.puremagic.com/issues/show_bug.cgi?id=4867 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 |
January 01, 2011 Re: Compiler error on struct with invariant and postblitz | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Sat, 01 Jan 2011 20:56:20 -0000, Jonathan M Davis <jmdavisProg@gmx.com> wrote: > 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 > http://d.puremagic.com/issues/show_bug.cgi?id=4867 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 Thank you. Sorry for arrows - Midnight Commander marks tabs with them, and I forgot to disable this. Filed bug: http://d.puremagic.com/issues/show_bug.cgi?id=5397 |
Copyright © 1999-2021 by the D Language Foundation