Black Lives Matter. Support the Equal Justice Initiative.

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

Documentation: cmd/link/internal/ld/testdata/deadcode

     1  // Copyright 2020 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  // Like ifacemethod2.go, this tests that a method *is* live
     6  // if the type is "indirectly" converted to an interface
     7  // using reflection with a method descriptor as intermediate.
     8  
     9  package main
    10  
    11  import "reflect"
    12  
    13  type S int
    14  
    15  func (s S) M() { println("S.M") }
    16  
    17  type I interface{ M() }
    18  
    19  type T float64
    20  
    21  func (t T) F(s S) {}
    22  
    23  func main() {
    24  	var t T
    25  	ft := reflect.TypeOf(t).Method(0).Type
    26  	at := ft.In(1)
    27  	v := reflect.New(at).Elem()
    28  	v.Interface().(I).M()
    29  }
    30  

View as plain text