Source file test/reflectmethodcheckptr.go
1 // run -gcflags=all=-d=checkptr=1 2 3 // Copyright 2026 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 package main 8 9 import "reflect" 10 11 type T struct{} 12 13 func (T) M() int { return 42 } 14 15 func main() { 16 v := reflect.ValueOf(T{}) 17 // Both paths construct a function value from a method's text offset. 18 // On wasm32, its code word is an integer function handle, not a pointer. 19 if got := v.Type().Method(0).Func.Call([]reflect.Value{v})[0].Int(); got != 42 { 20 panic("incorrect Type.Method result") 21 } 22 if got := v.Method(0).Call(nil)[0].Int(); got != 42 { 23 panic("incorrect Value.Method result") 24 } 25 } 26