Thread overview
Is this (or should it be) a bug?
Jul 06, 2005
Nick
Jul 06, 2005
Russ Lewis
Jul 08, 2005
Nick
Jul 06, 2005
Victor Nakoryakov
July 06, 2005
The following currently does not work (gives an ArrayBoundsError.)

> struct A
> {
>   int i;
> }
> void main()
> {
>   A[int] a;
>   a[10].i = 20;
> }

But is it reasonable to expect it to work? Should assigning a value to a struct member be enough to consider the struct an rvalue, thus adding it to the AA? What about calling struct members?

Nick


July 06, 2005
"Nick" <Nick_member@pathlink.com> wrote in message news:dagso2$2dkb$1@digitaldaemon.com...
> The following currently does not work (gives an ArrayBoundsError.)
>
>> struct A
>> {
>>   int i;
>> }
>> void main()
>> {
>>   A[int] a;
>>   a[10].i = 20;
>> }

I think you have to first assign a struct to the array element, i.e.

A[int] a;
A anA;
a[10]=anA;
a[10].i=20;

This works.


July 06, 2005
Nick wrote:
> The following currently does not work (gives an ArrayBoundsError.)
> 
> 
>>struct A
>>{
>>  int i;
>>}
>>void main()
>>{
>>  A[int] a;
>>  a[10].i = 20;
>>}
> 
> 
> But is it reasonable to expect it to work? Should assigning a value to a struct
> member be enough to consider the struct an rvalue, thus adding it to the AA?
> What about calling struct members?

I agree with you that assigning a value to a struct member should add the struct to the AA, however I'm skeptical about allowing somebody to call a member function.

The trouble, of course, is that your think, which looks like an assignment, might actually be calling a property.  Hmmm....
July 06, 2005
Nick wrote:
> The following currently does not work (gives an ArrayBoundsError.)
> 
> 
>>struct A
>>{
>>  int i;
>>}
>>void main()
>>{
>>  A[int] a;
>>  a[10].i = 20;
>>}
> 
> 
> But is it reasonable to expect it to work? Should assigning a value to a struct
> member be enough to consider the struct an rvalue, thus adding it to the AA?
> What about calling struct members?
> 
> Nick
> 
> 

As I know only opIndexAssign inserts new element if it does not exists yet, but not opIndex. In your snipet opIndex was called.

-- 
Victor (aka nail) Nakoryakov
nail-mail<at>mail<dot>ru

Krasnoznamensk, Moscow, Russia
July 08, 2005
In article <dah2pj$2ifp$1@digitaldaemon.com>, Russ Lewis says...
>
>I agree with you that assigning a value to a struct member should add the struct to the AA, however I'm skeptical about allowing somebody to call a member function.
>
>The trouble, of course, is that your think, which looks like an assignment, might actually be calling a property.  Hmmm....

I think allowing both assigning to variables and to properties should be enough to consider the struct an rvalue. Compare it to arrays, the following runs without error:

# void main()
# {
#   int[] list[char[]];
#   list["tiger"] ~= 10;
#   list["lion"].length = 5;
# }

but I currently cannot make my own structs work in the same way. Both assignments fail for a custom struct with length and opCatAssign.

Nick