1// Copyright 2015 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package main 6 7import ( 8 "./p" 9 "fmt" 10) 11 12type I interface { 13 Add(out *P) 14} 15 16type P struct { 17 V *int32 18} 19 20type T struct{} 21 22var x int32 = 42 23 24func Int32x(i int32) *int32 { 25 return &i 26} 27 28func (T) Add(out *P) { 29 out.V = p.Int32(x) // inlined, p.i.2 moved to heap 30} 31 32var PP P 33var out *P = &PP 34 35func F(s I) interface{} { 36 s.Add(out) // not inlined. 37 return out 38} 39 40var s T 41 42func main() { 43 println("Starting") 44 fmt.Sprint(new(int32)) 45 resp := F(s).(*P) 46 println("Before, *resp.V=", *resp.V) // Trashes *resp.V in process of printing. 47 println("After, *resp.V=", *resp.V) 48 if got, want := *resp.V, int32(42); got != want { 49 fmt.Printf("FAIL, got %v, want %v", got, want) 50 } 51} 52