-
Notifications
You must be signed in to change notification settings - Fork 492
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
Fix enum resolution #218
Fix enum resolution #218
Conversation
@technoweenie this is a good find, thank you very much for the contribution. A direct test would be great. Can you expand a bit more on how you ran into this issue and how you've tested the solution? I wonder how performance would differ if instead of parsing a format string, we tried to assert the - fmt.Fprintf(out, "%s", resolver)
+ if str, ok := resolver.(Stringer); ok { // can we do this on *reflect.Value?
+ out.WriteString(str)
+ } My gut feeling is that we'd come out slightly ahead if we didn't have to parse a format string. Thoughts? |
Got it 👍
I ran into it by trying to support an existing
No clue, worth a shot though. EDIT: I'll work on adding a test and experimenting with manually asserting |
3c5bc11
to
266323b
Compare
266323b
to
e5aa273
Compare
I've revised this pull with the following changes:
I can rip out the benchmark if you don't want it. It's pretty clear your suggestion was better than my initial version though:
|
+1 to this PR. I just ran into this issue and was considering implementing it myself until I saw this. To anyone else with this problem, fyi my current workaround is to change the resolver's return type to string, converting the enum right before the resolver returns. |
Please, resolve the conflicts in the PR. |
This benchmark was used to justify a tiny change in graph-gophers#218. Now that we all know the joys of fmt.Stringer, I don't see any reason to keep this file around, especially in the root package.
Thank you for your contribution |
This benchmark was used to justify a tiny change in graph-gophers#218. Now that we all know the joys of fmt.Stringer, I don't see any reason to keep this file around, especially in the root package.
…ution Fix enum resolution
This fixes an obscure issue of enum resolution. It currently uses
(*reflect.Value) String()
, which only works when the underlying type is a string. Otherwise it returns<%T value>
, even if the type implements the Stringer interface. The tests passed before and after the change. However, it wouldn't be a terrible idea to have more tests for enums implemented in different ways in Go.Let me know if there's anything I can do to get this merged. Happy to write more tests, or even look into a schema validation check that ensures all enums are implemented as
[]string
(in case you disagree that this is a bug).