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

     1  // Package locals tests bindings in local scopes.
     2  package locals
     3  
     4  // - @foo defines/binding Foo
     5  func foo() {
     6  	//- @alpha defines/binding Alpha1
     7  	//- Alpha1.node/kind variable
     8  	//- Alpha1 childof Foo
     9  	var alpha int
    10  
    11  	// Short declaration form introduces only new names.
    12  	// The others are references to their original definitions.
    13  	//
    14  	//- @bravo defines/binding Bravo
    15  	//- Bravo.node/kind variable
    16  	//- Bravo.subkind local
    17  	//- @alpha ref/writes Alpha1
    18  	//- !{@alpha defines/binding Alpha1}
    19  	alpha, bravo := 1, 2
    20  
    21  	// Bindings in a local scope shadow their enclosing scope.
    22  	//
    23  	//- @alpha defines/binding Alpha2
    24  	//- Alpha2.node/kind variable
    25  	//- Alpha2 childof Foo
    26  	for alpha := range []string{} {
    27  		// Verify that the inner binding shadows the outer.
    28  		//- @alpha ref Alpha2
    29  		_ = alpha
    30  	}
    31  
    32  	// Don't choke on blanks in short assignment forms.
    33  	//
    34  	//- @y defines/binding Val
    35  	//- Val.node/kind variable
    36  	for _, y := range []string{} {
    37  		//- @y ref Val
    38  		print(y)
    39  	}
    40  
    41  	//- @#0alpha defines/binding Alpha3
    42  	//- Alpha3.node/kind variable
    43  	//-
    44  	//- @#1alpha ref Alpha1
    45  	//- @#2alpha ref Alpha3
    46  	//- @bravo ref Bravo
    47  	if alpha := alpha + 3; alpha < bravo {
    48  		//- @bravo ref/writes Bravo
    49  		//- @alpha ref Alpha3
    50  		bravo = alpha
    51  	}
    52  
    53  	//- @alpha ref Alpha1
    54  	_ = alpha
    55  
    56  	//- @bravo ref Bravo
    57  	_ = bravo
    58  }