Files
golang.go/test/complit2.go
Robert Griesemer 30bfe53dd7 cmd/compile: enable promoted field selectors as keys in struct literals
Switch the generated UIR version from V2 to V3.
Adjust cmd/compile/internal/types to accept promoted field selectors
in composite literals.

Fixes #9859.

Change-Id: Ie314e28567cfa6cf4c9e962a07b32dd05b06bf5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/755740
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2026-03-19 17:16:38 -07:00

38 lines
560 B
Go

// run
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Verify that composite literals using selectors for
// embedded fields are assembled correctly.
package main
import "fmt"
type A struct {
a int
B
}
type B struct {
b string
C
}
type C struct {
c any
}
func main() {
eq(A{1, B{b: "foo"}}, A{a: 1, b: "foo"})
eq(A{B: B{C: C{c: "foo"}}}, A{c: "foo"})
}
func eq(x, y any) {
if x != y {
panic(fmt.Sprintf("%v != %v", x, y))
}
}