codekingpro/portable-devtools
114k
1// run2 3// Copyright 2016 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// The linker can prune methods that are not directly called or8// assigned to interfaces, but only if reflect.Type.MethodByName is9// never used. Test it here.10 11package main12 13import reflect1 "reflect"14 15var called = false16 17type M int18 19func (m M) UniqueMethodName() {20 called = true21}22 23var v M24 25type MyType interface {26 MethodByName(string) (reflect1.Method, bool)27}28 29func main() {30 var t MyType = reflect1.TypeOf(v)31 m, _ := t.MethodByName("UniqueMethodName")32 m.Func.Interface().(func(M))(v)33 if !called {34 panic("UniqueMethodName not called")35 }36}37 