Struct semantics

Promoted field selectors

A field is promoted when its selector is legal without spelling the embedded path. The shallowest matching field wins; equal-depth ambiguous selectors are invalid. Through Go 1.26, promoted names cannot serve directly as keys in outer composite literals. Example output: '5 2'.

Formal Syntax & Structure

go syntaxgo
outer.Field

Working Example

Example Snippetgo
package main
import "fmt"
type Inner struct{ ID int }type Outer struct {  Inner  ID int}
func main() {  x := Outer{Inner: Inner{ID: 2}, ID: 5}  fmt.Println(x.ID, x.Inner.ID)}
Go Reference