Radar · Go · Archive · Week 4 · Jan 19 – 25, 2026
Direct reference to embedded fields in struct literals
Worth knowinglanguage
- What changed
- The spec now allows keyed struct literals to refer directly to fields of embedded struct types (but not embedded pointer types). This generalizes “field names” in struct literals to “field selectors”, unifying struct literals with field assignments.
- Production impact
- The source does not say.
- Try it
- Write a struct with an embedded field and create a keyed literal using the embedded field’s name directly, e.g.
T{A: 1}. - Source
- github.com/golang/go/issues/9859
Understand it, then run it
Run it now
// This program demonstrates the new struct literal syntax that allows
// direct reference to embedded fields. It runs on Go 1.27.1.
package main
import "fmt"
type E struct{ A int }
type T struct{ E }
func main() {
// Using the new syntax: we can set A directly in the literal.
v := T{A: 42}
fmt.Println(v.A) // prints 42
}
What it printed when we ran it on Go 1.27.1
42
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed