Skip to content

reflect: Value.Method does not do the same nil checks as the language #32021

Description

@dotaheor

What version of Go are you using (go version)?

go version go1.12 linux/amd64

What did you do?

package main

import (
	"fmt"
	"reflect"
)

type S struct {
	x int
}
func (S) M(int) {}


type T struct {
	*S
}

func main() {
	var v = T{}
	
	t := reflect.TypeOf(v)
	fmt.Println(t, "has", t.NumMethod(), "methods:")
	for i := 0; i < t.NumMethod(); i++ {
		fmt.Print("  method#", i, ": ", t.Method(i).Type, "\n")
	}
	fmt.Println(reflect.ValueOf(v).Method(0)) // ok
	_ = v.M // panic
}

What did you expect to see?

Run okay.

What did you see instead?

panic.

Update: similarly for interface dynamic values

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status
    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions