Source file test/reflectmethod4.go

     1  // run
     2  
     3  // Copyright 2016 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  // The linker can prune methods that are not directly called or
     8  // assigned to interfaces, but only if reflect.Value.Method is
     9  // never used. Test it here.
    10  
    11  package main
    12  
    13  import "reflect"
    14  
    15  var called = false
    16  
    17  type M int
    18  
    19  func (m M) UniqueMethodName() {
    20  	called = true
    21  }
    22  
    23  var v M
    24  
    25  func main() {
    26  	reflect.ValueOf(v).Method(0).Interface().(func())()
    27  	if !called {
    28  		panic("UniqueMethodName not called")
    29  	}
    30  }
    31  

View as plain text