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

Some Enum question methods can collide #7084

Open
Fryguy opened this issue Nov 14, 2018 · 1 comment
Open

Some Enum question methods can collide #7084

Fryguy opened this issue Nov 14, 2018 · 1 comment

Comments

@Fryguy
Copy link
Contributor

Fryguy commented Nov 14, 2018

Since .underscore is used to create an Enum value's method name, it's possible to collide with existing method names. I'm not sure what the "right" solution is, but should the compiler raise an error (or warning) for situations like those in the following examples?

Example 1 - https://carc.in/#/r/5il3

enum MyEnum
  Nil
end

p MyEnum::Nil.nil? # => false (compiler level .nil? wins and is thus always false)

Example 2 - https://carc.in/#/r/5il6

enum MyEnum
  IsA  # or `RespondsTo` or `As`
end

p MyEnum::IsA.is_a? # => Syntax error in eval:5: expecting token 'CONST', not 'NEWLINE'
                    #    (compiler level .is_a? wins and so is syntactically incorrect)

Example 3 - https://carc.in/#/r/5il4

enum MyEnum
  Foo
  FOO
end

p MyEnum::Foo.foo? # => false
p MyEnum::FOO.foo? # => true  (last one always wins)
@bew
Copy link
Contributor

bew commented Nov 14, 2018

Note: using .EnumValue? methods (same up/down case as in the enum) would fix this.

It was suggested during the automatic cast (from literals) pr and was not considered as much as it could imo.

I'm on my phone, and no/t time/enough internet to check right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants