www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Is this (or should it be) a bug?

reply Nick <Nick_member pathlink.com> writes:
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
Jul 06 2005
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Jul 06 2005
prev sibling next sibling parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
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....
Jul 06 2005
parent Nick <Nick_member pathlink.com> writes:
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: 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
Jul 08 2005
prev sibling parent Victor Nakoryakov <nail-mail mail.ru> writes:
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
Jul 06 2005