2012-02-17 04:50:37 +00:00
|
|
|
// run
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-24 05:24:24 +00:00
|
|
|
// Test method invocation with pointer receivers and function-valued fields.
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-12-10 20:53:23 +00:00
|
|
|
type C struct {
|
2008-06-06 21:27:34 +00:00
|
|
|
a int;
|
2009-01-30 22:39:31 +00:00
|
|
|
x func(p *C)int;
|
2008-06-06 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 20:53:23 +00:00
|
|
|
func (this *C) f()int {
|
2008-06-06 21:27:34 +00:00
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
2009-12-10 20:53:23 +00:00
|
|
|
main() {
|
2008-06-06 21:27:34 +00:00
|
|
|
var v int;
|
|
|
|
var c *C;
|
|
|
|
|
2009-01-06 23:19:02 +00:00
|
|
|
c = new(C);
|
2008-06-06 21:27:34 +00:00
|
|
|
c.a = 6;
|
2009-01-30 22:39:31 +00:00
|
|
|
c.x = g;
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = g(c);
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = c.x(c);
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
|
|
|
|
v = c.f();
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 20:53:23 +00:00
|
|
|
func g(p *C)int {
|
2008-06-06 21:27:34 +00:00
|
|
|
var v int;
|
|
|
|
|
|
|
|
v = p.a;
|
2008-08-12 05:07:49 +00:00
|
|
|
if v != 6 { panic(v); }
|
2008-06-06 21:27:34 +00:00
|
|
|
return p.a;
|
|
|
|
}
|