Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
June 19, 2013 Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
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; } |
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deed | 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
|
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deed | 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) |
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | > /* SNIP */
>
>> int var() @property
>> {
>> return var;
>> }
>
> Isn't the problem in this property function? (Shouldn't it return _var :o)
that's also an error. changing to _var gives same result though..
|
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | Am 19.06.2013 13:40, schrieb Iain Buclaw:
> 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)
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; }
|
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deed | 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.
|
June 19, 2013 Re: Should it be a compile time error? | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | > 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 :(
|
Copyright © 1999-2021 by the D Language Foundation