golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/apidiff/testdata/structs.go (about)

     1  package p
     2  
     3  // old
     4  type S1 struct {
     5  	A int
     6  	B string
     7  	C bool
     8  	d float32
     9  }
    10  
    11  // new
    12  type S1 = s1
    13  
    14  type s1 struct {
    15  	C chan int
    16  	// i S1.C: changed from bool to chan int
    17  	A int
    18  	// i S1.B: removed
    19  	// i S1: old is comparable, new is not
    20  	x []int
    21  	d float32
    22  	E bool
    23  	// c S1.E: added
    24  }
    25  
    26  // old
    27  type embed struct {
    28  	E string
    29  }
    30  
    31  type S2 struct {
    32  	A int
    33  	embed
    34  }
    35  
    36  // new
    37  type embedx struct {
    38  	E string
    39  }
    40  
    41  type S2 struct {
    42  	embedx // OK: the unexported embedded field changed names, but the exported field didn't
    43  	A      int
    44  }
    45  
    46  // both
    47  type F int
    48  
    49  // old
    50  type S3 struct {
    51  	A int
    52  	embed
    53  }
    54  
    55  // new
    56  type embed struct{ F int }
    57  
    58  type S3 struct {
    59  	// i S3.E: removed
    60  	embed
    61  	// c S3.F: added
    62  	A int
    63  }
    64  
    65  // both
    66  type A1 [1]int
    67  
    68  // old
    69  type embed2 struct {
    70  	embed3
    71  	F // shadows embed3.F
    72  }
    73  
    74  type embed3 struct {
    75  	F bool
    76  }
    77  
    78  type alias = struct{ D bool }
    79  
    80  type S4 struct {
    81  	int
    82  	*embed2
    83  	embed
    84  	E int // shadows embed.E
    85  	alias
    86  	A1
    87  	*S4
    88  }
    89  
    90  // new
    91  type S4 struct {
    92  	// OK: removed unexported fields
    93  	// D and F marked as added because they are now part of the immediate fields
    94  	D bool
    95  	// c S4.D: added
    96  	E int // OK: same as in old
    97  	F F
    98  	// c S4.F: added
    99  	A1  // OK: same
   100  	*S4 // OK: same (recursive embedding)
   101  }
   102  
   103  // Difference between exported selectable fields and exported immediate fields.
   104  // both
   105  type S5 struct{ A int }
   106  
   107  // old
   108  // Exported immediate fields: A, S5
   109  // Exported selectable fields: A int, S5 S5
   110  type S6 struct {
   111  	S5 S5
   112  	A  int
   113  }
   114  
   115  // new
   116  // Exported immediate fields: S5
   117  // Exported selectable fields: A int, S5 S5.
   118  
   119  // i S6.A: removed
   120  type S6 struct {
   121  	S5
   122  }
   123  
   124  // Ambiguous fields can exist; they just can't be selected.
   125  // both
   126  type (
   127  	embed7a struct{ E int }
   128  	embed7b struct{ E bool }
   129  )
   130  
   131  // old
   132  type S7 struct { // legal, but no selectable fields
   133  	embed7a
   134  	embed7b
   135  }
   136  
   137  // new
   138  type S7 struct {
   139  	embed7a
   140  	embed7b
   141  	// c S7.E: added
   142  	E string
   143  }