Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
reflect: when MakeFunc returns, assign its results into the desired types #28761
This fails with a run-time panic:
It's quite confusing, as
To fix it, change
Should we instead upgrade the reflect package to do conversions when assigning the return values? We'd only do conversions that would be done during assignments under the language spec. Since there is nothing untyped at runtime, this would just be unnamed->named types, concrete->interface and interface->interface conversions, and bidirectional->unidirectional channels.
(Are we allowed to convert something that used to panic into something that now works?)
#6871 was a similar proposal that was rejected.
I personally think that it's intuitive, it's returning the concrete value. I think it also aligns well with how interfaces work (that interfaces should be made up of a concrete type and value).
I personally don't think it should do any implicit type conversions. It would have no way of knowing what we want to return, for instance if I want an
A few solutions -
It knows that, it was provided as the first argument to