Source file test/complit2.go

     1  // run
     2  
     3  // Copyright 2026 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Verify that composite literals using selectors for
     8  // embedded fields are assembled correctly.
     9  
    10  package main
    11  
    12  import "fmt"
    13  
    14  type A struct {
    15  	a int
    16  	B
    17  }
    18  
    19  type B struct {
    20  	b string
    21  	C
    22  }
    23  
    24  type C struct {
    25  	c any
    26  }
    27  
    28  func main() {
    29  	eq(A{1, B{b: "foo"}}, A{a: 1, b: "foo"})
    30  	eq(A{B: B{C: C{c: "foo"}}}, A{c: "foo"})
    31  }
    32  
    33  func eq(x, y any) {
    34  	if x != y {
    35  		panic(fmt.Sprintf("%v != %v", x, y))
    36  	}
    37  }
    38  

View as plain text