github.com/neugram/ng@v0.0.0-20180309130942-d472ff93d872/eval/testdata/method1.ng (about)

     1  f := func() {
     2  	panic("first f called")
     3  }
     4  
     5  four := 3
     6  
     7  {
     8  	methodik obj struct{} {
     9  		func (a) Read([]byte) (int, error) {
    10  			func N4() int { return four }
    11  			four := 6
    12  			_ = four
    13  			return N4(), nil
    14  		}
    15  	}
    16  	o := obj{}
    17  
    18  	four++
    19  
    20  	f = func() {
    21  		four := 5 // check we use the correctly scoped four
    22  		if v, _ := o.Read([]byte{3, 4}); v == 4 {
    23  			print("OK")
    24  		} else {
    25  			printf("v=%d, want 4\n", v)
    26  		}
    27  		_ = four
    28  	}
    29  }
    30  
    31  f()