Go Struct Embedding Gotcha: Ambiguous Fields

2025-09-22

Go's struct embedding, while powerful for composing types, presents a potential pitfall. When embedded structs share field names, like multiple embedded structs both having a `URL` field, the compiler unexpectedly prioritizes the least nested field. This code demonstrates this subtle issue, printing `abc.com` instead of a compilation error as might be expected. Exercise caution when using struct embedding to avoid ambiguous field names and potential runtime surprises.