Source file src/cmd/link/internal/ld/testdata/deadcode/ifacemethod6.go

     1  // Copyright 2023 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  
     5  // This test only uses MethodByName() with constant names
     6  // of methods to look up. These methods need to be kept,
     7  // but other methods must be eliminated.
     8  
     9  package main
    10  
    11  import "reflect"
    12  
    13  type S int
    14  
    15  func (s S) M() { println("S.M") }
    16  
    17  func (s S) N() { println("S.N") }
    18  
    19  type T float64
    20  
    21  func (t T) F(s S) {}
    22  
    23  func main() {
    24  	var t T
    25  	meth, _ := reflect.TypeOf(t).MethodByName("F")
    26  	ft := meth.Type
    27  	at := ft.In(1)
    28  	v := reflect.New(at).Elem()
    29  	methV := v.MethodByName("M")
    30  	methV.Call([]reflect.Value{v})
    31  }
    32  

View as plain text