Source file src/internal/types/testdata/spec/structLits.go
1 // Copyright 2026 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package p 6 7 type A struct { 8 a int 9 B 10 C 11 *D 12 } 13 14 type B struct { 15 b int 16 C 17 } 18 19 type C struct { 20 c int 21 D 22 } 23 24 type D struct { 25 x, y, z int 26 } 27 28 var ( 29 _ = &A{} 30 _ = &A{a: 0} 31 _ = A{A /* ERROR "unknown field A in struct literal of type A, but does have a" */ : 0} 32 _ = A{X /* ERROR "unknown field X in struct literal of type A, but does have x" */ : 0} 33 _ = A{a: 0, b: 0, c: 0} 34 _ = A{x /* ERROR "pointer indirection" */ : 0} 35 _ = B{b: 0, c: 0, x: 0, y: 0, z: 0} 36 _ = B{C: C{}, x /* ERROR "cannot specify promoted field x and enclosing embedded field C" */ : 0} 37 _ = A{b: 0, B /* ERROR "cannot specify embedded field B and enclosed promoted field b" */ : B{}} 38 _ = A{B: B{}, b /* ERROR "cannot specify promoted field b and enclosing embedded field B" */ : 0} 39 ) 40