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

     1  package p
     2  
     3  // apidiff's output (but not its correctness) could depend on the order
     4  // in which declarations were visited.
     5  
     6  // For example, this always correctly reported that U changed from T to U:
     7  
     8  // old
     9  type U = T
    10  
    11  // new
    12  // i U: changed from T to U
    13  type U T
    14  
    15  // both
    16  type T int
    17  
    18  // But the test below, which is just a renaming of the one above, would report
    19  // that B was changed from B to B! apidiff was not wrong--there is an
    20  // incompatibility here--but it expressed itself poorly.
    21  //
    22  // This happened because old.A was processed first (Scope.Names returns names
    23  // sorted), resulting in old.B corresponding with new.A. Later, when old.B
    24  // was processed, it was matched with new.B. But since there was already a
    25  // correspondence for old.B, the blame for the incompatibility was put on new.B.
    26  
    27  // The fix is to establish the correspondence between same-named types first.
    28  
    29  // old
    30  type A = B
    31  
    32  // new
    33  // i A: changed from B to A
    34  type A B
    35  
    36  // both
    37  type B int