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

     1  // Copyright 2026 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  // reflect.Value.MethodByName stored in a package variable by the static
     6  // initializer must keep all exported methods.
     7  
     8  package main
     9  
    10  import (
    11  	"os"
    12  	"reflect"
    13  )
    14  
    15  type T int
    16  
    17  func (T) M() {}
    18  
    19  var f = reflect.Value.MethodByName
    20  
    21  //go:noinline
    22  func call(v reflect.Value, name string) { f(v, name).Call(nil) }
    23  
    24  func main() { call(reflect.ValueOf(T(1)), os.Args[0]) }
    25  

View as plain text