github.com/akaros/go-akaros@v0.0.0-20181004170632-85005d477eab/test/ken/ptrfun.go (about)

     1  // run
     2  
     3  // Copyright 2009 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Test method invocation with pointer receivers and function-valued fields.
     8  
     9  package main
    10  
    11  type C struct {
    12  	a	int;
    13  	x	func(p *C)int;
    14  }
    15  
    16  func (this *C) f()int {
    17  	return this.a;
    18  }
    19  
    20  func
    21  main() {
    22  	var v int;
    23  	var c *C;
    24  
    25  	c = new(C);
    26  	c.a = 6;
    27  	c.x = g;
    28  
    29  	v = g(c);
    30  	if v != 6 { panic(v); }
    31  
    32  	v = c.x(c);
    33  	if v != 6 { panic(v); }
    34  
    35  	v = c.f();
    36  	if v != 6 { panic(v); }
    37  }
    38  
    39  func g(p *C)int {
    40  	var v int;
    41  
    42  	v = p.a;
    43  	if v != 6 { panic(v); }
    44  	return p.a;
    45  }