Skip to content

reflect: type of an interface is nil #35427

@kindermoumoute

Description

@kindermoumoute

I am trying to understand why this code works:

ioReaderType := reflect.ValueOf(struct{ ioReader io.Reader }{}).FieldByName("ioReader").Type()
fmt.Println(ioReaderType.String()) // prints "io.Reader"

But this one panic

ioReaderType := reflect.TypeOf(io.Reader(nil))
fmt.Println(ioReaderType.String()) // panic

https://play.golang.org/p/F2ndRax1f4E

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions