Thread overview
[Issue 2916] New: struct constructor use syntax undocumented
Apr 30, 2009
d-bugmail
Jan 23, 2012
Walter Bright
Jan 23, 2012
Kenji Hara
April 30, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2916

           Summary: struct constructor use syntax undocumented
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: steve.teale@britseyeview.com


This is probably just a documentation issue.

struct A
{
   int a;
   this(int n) { a = n; }
}

struct B
{
   int b;
   this(int n) { b = n; }
}

struct C
{
   A a;
   B b;
   this(int n, int m)
   {
      a = A(n);
      b = B(m);
   }
}


struct D
{
   A a;
   B b;
   this(int n, int m)
   {
      a(n);
      b(m);
   }
}

void main()
{
   C c = C(2, 3);
   writefln("C:a = %d, C:b = %d", c.a.a, c.b.b);

   D d = D(2, 3);
   writefln("D:a = %d, D:b = %d", d.a.a, d.b.b);
}

D is essentially the same as C, but uses a(n) instead of a = A(n).  Both
compile, but the former has no effect on the A member.

Output:
C:a = 2, C:b = 3
D:a = 0, D:b = 0

The documentation should mention the correct syntax, and explain what a(n) means, or the compiler should object to that form.


-- 

January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2916


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2012-01-23 00:57:33 PST ---
This is a compiler bug that a(n) is accepted, it is not a documentation
problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2916


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-23 04:59:33 PST ---
The constructor call from an instance is invalid.

*** This issue has been marked as a duplicate of issue 6036 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------