-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: decide, document whether custom Type implementations are supported #32303
Comments
The documentation does say:
That was added for #16348 in 2016. It's not obvious to me that that can be reconciled with user-defined |
It's not obvious to me that you couldn't argue that your own type was its own type, and couldn't just be comparable (to itself). I don't think that sentence is enough documentation. |
I don't think we should try to support people who define their own implementation of |
hi, Author of said naughty functions here. I think it should be supported, albeit in a slightly different form. First I provide a high level motivation, followed by examples, a rationalization and two possible solutions. The Gorgonia For example, I have written a CKY-style parser that relies on tensor operations of spans of texts; formal logics systems where tensor operations performed on logical forms; and many more. The Extension example in https://godoc.org/gorgonia.org/tensor provides the most concrete use case of Where it's used is mainly in the So why is Solutions to the current situation is quite easy to fix: we can just destructure the The whole situation can further be remedied by having an unexported sealing method in How this plays with different implementations, I have no idea. |
Yes, I think this is better. |
@chewxy, I think I understand why it's useful to have Dtype, but why is it useful that Dtype itself implement
This is already the case. @bradfitz said:
I don't really understand in what sense this has ever worked. I believe every exported function of |
That was a big assumption on my part because: a) that tensor code exists, and I assumed it wouldn't have been submitted somewhere if it didn't work, b) a CL was sent to fix it. So I assumed it used to work and recently stopped. |
|
Good find. |
I think the issue is pretty settled now, I'm happy with the current solution (@cherrymui 's comment). Allow me however to answer a query from @aclements
|
We never intended custom Type implementations to be supported. If there were some way to disallow reflect.Type from being embedded, I would do it. I don't think we should make any promises that that's OK. |
* Fixed Travis * Fixed reflect type issue per golang/go#32303
Does the reflect package support users who implement Type themselves?
https://golang.org/pkg/reflect/#Type has unexported methods, but it's still possible to implement it by embedding a reflect.Type and using the normal (
*rtype
) type.The documentation doesn't say that it's not allowed, but apparently people do it:
This apparently worked (enough? kinda?) at some point, and then we broke it, probably because we never imagined somebody would do this. That led to sending https://golang.org/cl/179338
This bug is to decide whether that's supported and to document. If it's supported, it needs tests.
/cc @ianlancetaylor @rsc @bcmills @randall77 @aclements @cherrymui
The text was updated successfully, but these errors were encountered: