Ran into a problem where an interface of underlying type "string" is
silently converted to an interface of underlying type "reflect.Value".
And an eventual panic message pointed to a completely different
location/cause.
Simplified Play example.Raised a number of questions
A typed interface, X in this case, is not type specific to its underlying type? Seems so, since the problem assignment
does not cause an immediate error even if x is explicitly created by
x := reflect.ValueOf(s).Interface()
Is
there a reason not to extend the type system to verifying the type of
at least the first level of underlying type of an interface value?
The
promotion of a value to an interface does not promote the underlying
type value to the interface when the value is already a reflect.Value?
That is, reflect.Value is nominally an underlying type value container.
Does an interface value with an underlying type of reflect.Value ever
make sense? If it does, seems like there should be some path for
getting at the second level underlying type
x = mischief(x)
x = reflect.ValueOf(x).InterfaceOfNextLevelUnderlyingType()
Is there an existing reflection way of doing this?