> Yes, in the literal narrow sense, there is no such thing in the submitted article
Therefore your analogy is invalid, because your example is doing something entirely different and throws away nested structs that the whole thing is about.
> The point is that the exhibited behaviour is unintuitive, in contrast to what the others are saying.
Why?
> Did I get that right?
No. Let's stick to the original example and add the order of operations from your example.
type A struct {
X string
}
type Nested struct {
X string
}
type B struct {
Nested
}
type Combined struct {
A
B
}
c := Combined{}
c.X = "example.com"
c.Nested.X = "something completely different"
fmt.Println(c.X)
Do you still expect this to print "something completely different" or does this look intuitive now?The unintuitive part is that this works in the first place and doesn't throw an error:
type Combined struct {
//A
B
}
c := Combined{}
//c.X = "example.com"
c.Nested.X = "something completely different"
fmt.Println(c.X)
But if you know about this unintuitive feature and are relying on it instead of accessing the fields by their fully qualified names, then you should already have a gnawing feeling that asks you "what happens when there are conflicts?" (and the answer is - it does the intuitive thing)