D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2916 - struct constructor use syntax undocumented
Summary: struct constructor use syntax undocumented
Status: RESOLVED DUPLICATE of issue 6036
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-04-30 05:09 UTC by Steve Teale
Modified: 2015-06-09 01:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steve Teale 2009-04-30 05:09:12 UTC
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.
Comment 1 Walter Bright 2012-01-23 00:57:33 UTC
This is a compiler bug that a(n) is accepted, it is not a documentation problem.
Comment 2 Kenji Hara 2012-01-23 04:59:33 UTC
The constructor call from an instance is invalid.

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