[Issue 13945] New: Documentation and errors of nested structs need improvement

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jan 6 13:59:51 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13945

          Issue ID: 13945
           Summary: Documentation and errors of nested structs need
                    improvement
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: websites
          Assignee: nobody at puremagic.com
          Reporter: peter.alexander.au at gmail.com

Some example code:

----------------------
struct A(T) {
  T x;
  this(int) {}  // Error: field x must be initialized in constructor, because
it is nested struct
}

void bar(T)() {
  T y;  // Error: cannot access frame pointer of foo.main.X
}

void main() {
  struct X {
    this(int) {}
  }
  bar!X();
  A!X(1);
}
----------------------

I can find no explanation of why these errors would occur in the documentation.

Furthermore, the errors are uninformative. Ok, so T is a nested struct. Why do
I have to initialize it in the constructor? What is a "frame pointer" and why
does it need to access it to construct the object? (frame pointer is an
implementation detail, and such terminology should not be exposed to the user).

To resolve this bug, I'd like to see two things:

1) Documentation of *why* nested structs need special initialization, and
precise definition of what counts as initialization. I know there are
limitation with using loops, and calling other functions, but this is
documented no where as far as I can see.

2) Improved error message. For these, I would prefer something along the lines
of:

"Error: field x must be initialized directly in constructor from another
instance of T, since it is a nested struct and requires its outer context"

"Error: y must be constructed from another instance of T, since it is a nested
struct and requires context"

These are just ideas.

--


More information about the Digitalmars-d-bugs mailing list