...

Source file src/cmd/link/internal/ld/testdata/deadcode/ifacemethod.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  // Test that a method of a reachable type is not necessarily
     6  // live even if it matches an interface method, as long as
     7  // the type is never converted to an interface.
     8  
     9  package main
    10  
    11  type I interface{ M() }
    12  
    13  type T int
    14  
    15  func (T) M() { println("XXX") }
    16  
    17  var p *T
    18  var e interface{}
    19  
    20  func main() {
    21  	p = new(T) // used T, but never converted to interface in any reachable code
    22  	e.(I).M()  // used I and I.M
    23  }
    24  
    25  func Unused() { // convert T to interface, but this function is not reachable
    26  	var i I = T(0)
    27  	i.M()
    28  }
    29  
    30  var Unused2 interface{} = T(1) // convert T to interface, in an unreachable global initializer
    31  

View as plain text