kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/indexer/testdata/basic/anonymous.go (about)

     1  // Package anon tests properties of anonymous types.
     2  //
     3  // Parameters and variables can be declared with anonymous types that are
     4  // specified as part of their declaration. In the body of functions and of
     5  // initializers, those fields may have references that we'd like to capture.
     6  package anon
     7  
     8  // - @planx defines/binding Planx
     9  // - Planx.node/kind variable
    10  func f(planx struct {
    11  	//- T.node/kind variable
    12  	//- T.subkind field
    13  	//- @+3"T" defines/binding T
    14  
    15  	// Count of thingies.
    16  	T int
    17  
    18  	// If they wrote comments, grab them, because heaven knows nobody is going
    19  	// to understand this without 'em.
    20  	//
    21  	//- TDoc documents T
    22  	//- TDoc.node/kind doc
    23  	//- TDoc.text "Count of thingies."
    24  }) int {
    25  	//- @T ref T
    26  	//- @planx ref Planx
    27  	return planx.T
    28  }
    29  
    30  // - @Struct defines/binding Struct
    31  // - Struct.node/kind variable
    32  var Struct = struct {
    33  	//- @V defines/binding V
    34  	//- V.node/kind variable
    35  	//- V.subkind field
    36  	V int
    37  }{
    38  	//- @V ref/writes V
    39  	V: 25,
    40  }
    41  
    42  // - @V ref V
    43  var _ = Struct.V
    44  
    45  var w struct {
    46  	//- @X defines/binding X
    47  	//- X.node/kind variable
    48  	//- X.subkind field
    49  	X uint32
    50  }
    51  
    52  // - @X ref X
    53  var _ = w.X
    54  
    55  var y struct {
    56  	//- @Y defines/binding Y
    57  	//- Y.node/kind variable
    58  	//- Y.subkind field
    59  	Y int
    60  } = struct {
    61  	//- @Y defines/binding Y2
    62  	//- !{ @Y defines/binding Y
    63  	//-    @Y ref Y }
    64  	Y int
    65  	// TODO(schroederc): investigate joining the duplicate anon types
    66  }{
    67  	//- @Y ref/writes Y2
    68  	Y: 25,
    69  }
    70  
    71  // - @Y ref Y
    72  var _ = y.Y
    73  
    74  // - @elt defines/binding Elt
    75  // - Elt.node/kind variable
    76  var g = func(elt struct {
    77  	//- @P defines/binding P
    78  	//- P.node/kind variable
    79  	//- P.subkind field
    80  	P string
    81  }) int {
    82  	//- @P ref P
    83  	//- @elt ref Elt
    84  	return len(elt.P)
    85  }
    86  
    87  // - @em defines/binding Em
    88  // - Em.node/kind record
    89  type em struct {
    90  	v struct {
    91  		//- @X defines/binding EmX
    92  		//- EmX.node/kind variable
    93  		//- EmX.subkind field
    94  		X string
    95  	}
    96  }
    97  
    98  // - @api defines/binding API
    99  // - API.node/kind variable
   100  func h(api interface {
   101  	//- @M defines/binding M
   102  	//- M.node/kind function
   103  	M() int
   104  }) int {
   105  	//- @M ref M
   106  	//- @api ref API
   107  	return api.M()
   108  }