1// run 2 3// Copyright 2018 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 7package main 8 9import ( 10 "runtime" 11 "strings" 12) 13 14type Func func() 15 16func (f Func) Foo() { 17 if f != nil { 18 f() 19 } 20} 21 22func (f Func) Bar() { 23 if f != nil { 24 f() 25 } 26 buf := make([]byte, 4000) 27 n := runtime.Stack(buf, true) 28 s := string(buf[:n]) 29 if strings.Contains(s, "-fm") { 30 panic("wrapper present in stack trace:\n" + s) 31 } 32} 33 34func main() { 35 foo := Func(func() {}) 36 foo = foo.Bar 37 foo.Foo() 38} 39