class invariants and property declarations

2011-02-16 Thread Michael Engelhardt
Hi, I just have started diving in D. Exploring the contract feature I stumbled upon the fact that a class invariant does not apply to properties: import std.stdio; void main(string[] args) { Time t = new Time(); t.hours = 24; // works; why? writeln("t.hours is ", t.hours); t.add(1

Re: class invariants and property declarations

2011-02-16 Thread Dmitry Olshansky
On 16.02.2011 11:03, Michael Engelhardt wrote: Hi, I just have started diving in D. Exploring the contract feature I stumbled upon the fact that a class invariant does not apply to properties: Welcome on board :) Invariant gets called on every public method call (at begin & end if I'm not mista

Re: class invariants and property declarations

2011-02-16 Thread Jesse Phillips
Dmitry Olshansky Wrote: > Now to properties, this is actually shouldn't be allowed: > > @property int hours; > > @property is a annotation applied to functions (getter/setter), to allow > calling it with omitted () and a natural assign syntax like this: Why shouldn't it be allowed? While it

Re: class invariants and property declarations

2011-02-16 Thread Dmitry Olshansky
On 16.02.2011 20:47, Jesse Phillips wrote: Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natural assign syntax like this: Why

Re: class invariants and property declarations

2011-02-16 Thread Jonathan M Davis
On Wednesday, February 16, 2011 09:47:32 Jesse Phillips wrote: > Dmitry Olshansky Wrote: > > Now to properties, this is actually shouldn't be allowed: > > @property int hours; > > > > @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natur

Re: class invariants and property declarations

2011-02-16 Thread Steven Schveighoffer
On Wed, 16 Feb 2011 12:47:32 -0500, Jesse Phillips wrote: Dmitry Olshansky Wrote: Now to properties, this is actually shouldn't be allowed: @property int hours; @property is a annotation applied to functions (getter/setter), to allow calling it with omitted () and a natural assign syn

Re: class invariants and property declarations

2011-02-17 Thread Jesse Phillips
Jonathan M Davis Wrote: > Except that @property is for _functions_. You mark a function with @property > so > that it _acts_ like a variable. @property on a variable is _meaningless_. It > would be like marking a variable nothrow. It makes no sense. Neither should > be > legal. The fact that

Re: class invariants and property declarations

2011-02-17 Thread Jonathan M Davis
On Thursday, February 17, 2011 10:39:20 Jesse Phillips wrote: > Jonathan M Davis Wrote: > > Except that @property is for _functions_. You mark a function with > > @property so that it _acts_ like a variable. @property on a variable is > > _meaningless_. It would be like marking a variable nothrow.