Thread overview
dmd 101: crash
Sep 12, 2004
Regan Heath
Sep 13, 2004
Tyro
Sep 13, 2004
Regan Heath
Sep 13, 2004
Tyro
September 12, 2004
class A {
  const int b;
  this()
  {
    b = 2;
  }
}

void main()
{
  A a = new A();
  a.b = 5; //remove this line, no crash
}

D:\D\src\temp>dmd const.d
const.d(5): b is not an lvalue
<crash>

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
September 13, 2004
Regan Heath wrote:

> class A {
>   const int b;
>   this()
>   {
>     b = 2;
>   }
> }
> 
> void main()
> {
>   A a = new A();
>   a.b = 5; //remove this line, no crash
> }
> 
> D:\D\src\temp>dmd const.d
> const.d(5): b is not an lvalue
> <crash>
> 
> Regan
> 
Isn't this intended behavior? A const must be defined not declared (ie., It's value must be know upon first encounter).  And once known, such value cannot be overridden.

Andrew
September 13, 2004
On Sun, 12 Sep 2004 21:37:56 -0400, Tyro <ridimz_at@yahoo.dot.com> wrote:
> Regan Heath wrote:
>
>> class A {
>>   const int b;
>>   this()
>>   {
>>     b = 2;
>>   }
>> }
>>
>> void main()
>> {
>>   A a = new A();
>>   a.b = 5; //remove this line, no crash
>> }
>>
>> D:\D\src\temp>dmd const.d
>> const.d(5): b is not an lvalue
>> <crash>
>>
>> Regan
>>
> Isn't this intended behavior? A const must be defined not declared (ie., It's value must be know upon first encounter).  And once known, such value cannot be overridden.

Yes, the error is correct, line 5 is "b = 2;" in the ctor for the class. However, the compiler crashes when it sees the "a.b = 5;" line, that is the bug.

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
September 13, 2004
> Yes, the error is correct, line 5 is "b = 2;" in the ctor for the class. However, the compiler crashes when it sees the "a.b = 5;" line, that is the bug.
> 
> Regan
> 

I C. Thanks for clarifying!

Andrew