Thread overview
opIndex in struct
Jul 15, 2004
Bent Rasmussen
Jul 15, 2004
Stewart Gordon
Jul 15, 2004
Bent Rasmussen
July 15, 2004
>dmd test.d
test.d(15): cannot implicitly convert int to test


struct test
{
    bit x;
    bit opIndexAssign(bit v, uint i)
    {
        return x = v;
    }
    void ex()
    {
        this[0] = true; // oops
    }
}

The error does not manifest if test is a class.

DMD 0.95 XP SP1


July 15, 2004
Bent Rasmussen wrote:

>> dmd test.d
> 
> test.d(15): cannot implicitly convert int to test

There aren't 15 lines in your code.  So we have yet another line numbering bug?

> struct test
> {
>     bit x;
>     bit opIndexAssign(bit v, uint i)
>     {
>         return x = v;
>     }
>     void ex()
>     {
>         this[0] = true; // oops
>     }
> }
> 
> The error does not manifest if test is a class.

I think it's an issue with this in struct actually.

In a struct, this means the address of the current object.  Don't ask me why.

	(*this)[0] = true;

should work.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.
July 15, 2004
> There aren't 15 lines in your code.  So we have yet another line numbering bug?

No. I just sliced the relevant piece of the code to make the case shorter, and inserted a comment on the interesting line. I didn't figure this was relevant

module test;

...

void main
{
}

> I think it's an issue with this in struct actually.
>
> In a struct, this means the address of the current object.  Don't ask me why.
>
> (*this)[0] = true;
>
> should work.

Thanks. Excuse the noise. :-)