Skip to content
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

Can't parse enum from upcase word #3108

Closed
wants to merge 1 commit into from

Conversation

jeromegn
Copy link
Contributor

@jeromegn jeromegn commented Aug 7, 2016

I'm not sure if this was the case before. I don't know if this is a bug or just misdocumented, but I expect there are not tests for it or else they would fail.

Due to the camelcasing, it won't convert "BLUE" into "Blue", it outputs "BLUE" which is not found in the enum. However, using a lowercase "blue" works because that gives "Blue".

I'm not sure if this was the case before. I don't know if this is a bug or just misdocumented, but I expect there are not tests for it or else they would fail.

Due to the camelcasing, it won't convert `"BLUE"` into `"Blue"`, it outputs `"BLUE"` which is not found in the enum. However, using a lowercase `"blue"` works because that gives `"Blue"`.
@jhass
Copy link
Member

jhass commented Aug 7, 2016

👍 from me. @asterite what was the intended behavior here? Do we want to support an enum like

enum Foo
  Bar
  BAR
end

here or should parse just return the first match regardless of any casing?

@asterite
Copy link
Member

asterite commented Aug 8, 2016

I think parse should be case-insensitive, I can't remember why it uses camelcase, maybe to parse "foo_bar" into "FooBar", but that probably doesn't make sense.

I would discourage enums with Bar and BAR as members. We could even have the compiler give an error in that case because it's pretty confusing (if the downcased names conflict). What do you think?

@jhass
Copy link
Member

jhass commented Aug 8, 2016

Fine with me if we prefer the explicit names over the autogenerated ones in the case of flag enums, that is just silently don't autogenerate anything if it would conflict.

@jhass jhass added the kind:docs label Aug 8, 2016
@Sija
Copy link
Contributor

Sija commented Aug 8, 2016

@asteritesnake_case is used quite often so I'd be 👍 for keeping the conversion as is.

@jeromegn
Copy link
Contributor Author

jeromegn commented Aug 8, 2016

My use case was for converting something like: "TASK_RUNNING" to "Running"
of an enum "TaskState".

I added a method to my enum to strip a prefix "TASK_", downcase and then
parse.

Anyway, I just wanted to correct the docs if they were broken. Changing the
code would be ok too.
On Mon, Aug 8, 2016 at 3:25 PM Sijawusz Pur Rahnama <
notifications@github.com> wrote:

@asterite https://github.com/asteritesnake_case is used quite often so
I'd be 👍 for keeping the conversion as is.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3108 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACpPR-OzhLFGiIsR7wu9UjyV_POQ4hXks5qd57XgaJpZM4JefEH
.

@asterite asterite closed this in ed6dd2e Aug 9, 2016
asterite pushed a commit that referenced this pull request Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants