Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reflect: MakeFunc can't handle return values which are the zero Value #28748

randall77 opened this issue Nov 12, 2018 · 2 comments


Copy link

commented Nov 12, 2018

package main

import "reflect"

func main() {
	r := reflect.MakeFunc(reflect.TypeOf(func() error { return nil }),
		func(args []reflect.Value) []reflect.Value {
			var x [1]reflect.Value
			return x[:]
		}).Interface().(func() error)

This code will cause the r() call to panic with a nil pointer dereference. We should really panic with something sensible instead.

The code is trying to provide a sensible panic, but panics when trying to build that panic message. It gets to here:

			if v.typ != typ {
				panic("reflect: function created by MakeFunc using " + funcName(f) +
					" returned wrong type: have " +
					out[i].typ.String() + " for " + typ.String())

But v.typ is nil, so out[i].typ.String() (v and out[i] are the same) panics inside (*rtype).String.

This has been the case since at least go 1.2. Marking for 1.13.

@randall77 randall77 added this to the Go1.13 milestone Nov 12, 2018


This comment has been minimized.

Copy link
Contributor Author

commented Nov 13, 2018

See also #6871.


This comment has been minimized.

Copy link

commented May 6, 2019

Change mentions this issue: reflect: special-case panic message when returning Value{} from MakeFunc function

@gopherbot gopherbot closed this in 04845fe May 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.