-
Notifications
You must be signed in to change notification settings - Fork 923
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
src/reflect: implement rawType.Name() #2479
Conversation
In good news with this merged I am able to use json :)
before
after
|
@Sean-Der can you please rebase this branch against |
@deadprogram done! |
Can you please add a test of this somewhere? |
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Float32, Float64, Complex64, Complex128, String: | ||
return kind.String() | ||
default: | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document that we don't yet support named types, and so this fix is only partial support.
I'm not sure I agree with this change. I've considered it before but rejected the idea because while it gets the encoding/json package to mostly work, it is somewhat incorrect. |
Any idea when this pullrequest is accepted? Actually quite a lot depends on it e.g. the parsing of x.509 certificate. We need this to write WASM filters for Istio. Without the crypto package, which needs this fix, TinyGo is almost worthless for WASM. |
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Float32, Float64, Complex64, Complex128, String: | ||
return kind.String() | ||
default: | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would rather panic here, to make it explicit we do not support this type?
return "" | |
panic("unimplemented: (reflect.Type).Name()") |
Specifically, what I'm worried about with this PR is that it is not correct for named types. For unnamed types it seems to be correct (it just returns the underlying type name like A partial solution might be to detect whether the type is named and panic if it is, returning the underlying type name if it is not named. But I'm afraid this won't solve the problem for serialization libraries. |
@aykevl I am happy to add tests/modify how we do this to get it merged :) JSON I think matters a lot for JSON users (probably not so much for the small devices) I ended up not using the stdlib json because of how big it made the binary size. I switched to github.com/moznion/go-json-ice |
I think support for unnamed types is better than no support at all which is in line with @aykevl. I am up to drive the PR towards such direction, tests included. |
case Bool, Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Float32, Float64, Complex64, Complex128, String: | ||
return kind.String() | ||
default: | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather do this
return "" | |
panic("unimplemented for named types: (reflect.Type).Name()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, we had a discussion in this thread on slack with @aykevl. There is one PR refactoring the reflect package that is in the waiting room :) So it will change after the PR is merged... I am unsure about the delays concerning the merge of the PR.
Is it possible to proceed with this, even if a longer term, larger PR may happen in the future? As probably some notice, there's an increase of people trying and failing to use TinyGo with wasm, sometimes leaving the Go language entirely as a result. It would seem like "cutting of one's nose to spite their face" to not proceed tactically even if a more strategic change could happen one day. I suspect to move this forward, we need someone with commit access to wave their hand and say "I'll help" and give whatever feedback is needed to the authors, as it seems the authors are ready. How about it? |
I still don't agree with merging incorrect code. This PR, while well intentioned, will result in broken code. A relatively simple way forward is by returning "" for non-named types and panicking for named types. You can determine the difference between the two using the documentation at the top of src/reflect/types.go. Feel free to ask if something is unclear. |
@aykevl maybe close out this then? open PRs are distracting especially in reflect which is spread across so many things. I think that people knowing what won't happen is at least direction giving. |
Superseded by #3498 |
No description provided.