Allow composite literals without an explicit type
Go lets you omit the type of a composite literal only in a few places, such as elements nested inside a slice or map literal. Everywhere else you must spell out the type, even when the compiler already knows it. This is verbose with long type names like generated protobuf types, and it rules out anonymous struct types for things like function arguments.
The proposal makes the type in a composite literal optional. An untyped literal {...} is assignable to a type T if T{...} with the same elements would be a valid composite literal of type T. Pointer types are handled the same way. The literal has no default type, so x := {1, 2, 3} is an error. This replaces the spec's special rules for eliding element types.
var m map[string]int = {"a": 1}
type Args struct{ A, B, C int }
func Foo(args Args) { ... }
Foo({A: 1, B: 2, C: 3})
return {}, err // instead of time.Time{}, err
p.Options = append(p.Options, {...}) // type inferred from the slice
- Proposal
- #12854 by neild
- Status
- Implemented on Nov 10, 2026
- Release
- Go 1.28
- Impact
- high
- Area
- spec