digitalmars.D.learn - Should it be a compile time error?
- deed (19/19) Jun 19 2013 The following compiles and crashes with DMD 2.063.
- bearophile (5/6) Jun 19 2013 In general it's not easy for a D compiler to perform that kind of
- Iain Buclaw (4/13) Jun 19 2013 Isn't the problem in this property function? (Shouldn't it
- deed (1/8) Jun 19 2013 that's also an error. changing to _var gives same result though..
- dennis luehring (5/21) Jun 19 2013 that isn't the problem - D allows assignment to an read property - and
- dennis luehring (1/5) Jun 19 2013 sorry i've totaly lost seeing the write property :(
- John Colvin (8/9) Jun 19 2013 Yes it should, in an ideal world. Expanding out the assign
The following compiles and crashes with DMD 2.063. Should this be a compile time error? class A { int _var; void var(int i) property { this.var = i; // oops, crashes. } // should have been this._var int var() property { return var; } } void main() { auto a = new A(); a.var = 3; }
Jun 19 2013
deed:Should this be a compile time error?In general it's not easy for a D compiler to perform that kind of validation. Bye, bearophile
Jun 19 2013
On Wednesday, 19 June 2013 at 11:33:43 UTC, deed wrote:The following compiles and crashes with DMD 2.063. Should this be a compile time error? class A { int _var;/* SNIP */int var() property { return var; }Isn't the problem in this property function? (Shouldn't it return _var :o)
Jun 19 2013
/* SNIP */that's also an error. changing to _var gives same result though..int var() property { return var; }Isn't the problem in this property function? (Shouldn't it return _var :o)
Jun 19 2013
Am 19.06.2013 13:40, schrieb Iain Buclaw:On Wednesday, 19 June 2013 at 11:33:43 UTC, deed wrote:that isn't the problem - D allows assignment to an read property - and there is no write property around, so it should be an compiletime error i should compile only if the missing write property is available - or? property int var(int value) { return _var = value; }The following compiles and crashes with DMD 2.063. Should this be a compile time error? class A { int _var;/* SNIP */int var() property { return var; }Isn't the problem in this property function? (Shouldn't it return _var :o)
Jun 19 2013
that isn't the problem - D allows assignment to an read property - and there is no write property around, so it should be an compiletime error i should compile only if the missing write property is available - or? property int var(int value) { return _var = value; }sorry i've totaly lost seeing the write property :(
Jun 19 2013
On Wednesday, 19 June 2013 at 11:33:43 UTC, deed wrote:Should this be a compile time error?Yes it should, in an ideal world. Expanding out the assign property, what we've got is: void var(int i) { var(i); // endless recursion. } Linux segfaults on stack overflow, so that's your crash.
Jun 19 2013