Sorry.
I was pointing out that it would seem that if I can initialize an
object like this:
p := new(Point);
p.X = 1;
p.Y = 2;
p.Z = 3;
then I should be able to initialize it like this:
p := &Point{ X: 1, Y: 2, Z: 3};
but I can't if T is declared
type Point2D struct {
X int;
Y int;
}
type Point struct {
Point2D;
Z int;
}
The expected way is:
p := &Point{Point2D: Point2D{X: 1, Y: 2}, Z: 3};
I was saying that requiring it to be structured this way when
initializing like this:
p := &Point{Point2D{1, 2}, 3};
makes sense, because the whole basis of the unkeyed literal is
structural, but it seems inconsistent to have to structure the literal
when initializing using keys, since the keyed literal is inherently
non-structural, and that it would be more consistent to use the
selector for a field as its key, irrespective of whether it belongs to
the struct itself or to an embedded struct.
I was wondering whether this makes sense, or if I'm missing something.
(not "the key is not the selector", thats a truism by default and
means nothing)
The second part was more hypothetical and was talking about, if keys
were the selectors as considered above, what to do if the embedded
type is a pointer, as in, either require explicit initialization, or
allow implicit initialization. I was trying to come up with a negative
side effect of the implicit initialization (such as the pointer itself
not being exported), but couldn't come up with a strong one. This is,
however sort of an addendum to the first question and not really the
main point.