Thread overview
DMD 0.130: Properties don't access opIndexAssign overload
Sep 07, 2005
Burton Radons
Sep 08, 2005
zwang
Sep 10, 2005
Thomas Kühne
September 07, 2005
This code fails compilation with the error message "p.property()[4]" is not an lvalue.  It is valid code.

        struct Array
        {
                int opIndex (int a) { return a; }
                int opIndexAssign (int a, int b) { return a; }
        }

        struct Property
        {
                Array property () { Array a; return a; }
        }

        void test ()
        {
                Property p;

                p.property [4] = 8;
        }


September 08, 2005
Burton Radons wrote:
> This code fails compilation with the error message "p.property()[4]" is not
> an lvalue.  It is valid code.
> 
>         struct Array
>         {
>                 int opIndex (int a) { return a; }
>                 int opIndexAssign (int a, int b) { return a; }
>         }
>                 struct Property
>         {
>                 Array property () { Array a; return a; }
>         }
>                 void test ()
>         {
>                 Property p;
>                         p.property [4] = 8;
>         }
> 
> 

This is an old bug. The workaround I used is to write parentheses explicitly like p.property()[4] = 8;
September 10, 2005
Burton Radons schrieb:
> This code fails compilation with the error message "p.property()[4]" is not an lvalue.  It is valid code.
> 
>         struct Array
>         {
>                 int opIndex (int a) { return a; }
>                 int opIndexAssign (int a, int b) { return a; }
>         }
> 
>         struct Property
>         {
>                 Array property () { Array a; return a; }
>         }
> 
>         void test ()
>         {
>                 Property p;
> 
>                 p.property [4] = 8;
>         }

Added to DStress as http://dstress.kuehne.cn/run/o/opIndexAssign_02_A.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_B.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_C.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_D.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_E.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_F.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_G.d http://dstress.kuehne.cn/run/o/opIndexAssign_02_H.d

Thomas