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

Support inheriting enums #7632

Open
vladfaust opened this issue Apr 5, 2019 · 4 comments
Open

Support inheriting enums #7632

vladfaust opened this issue Apr 5, 2019 · 4 comments

Comments

@vladfaust
Copy link
Contributor

vladfaust commented Apr 5, 2019

Extracted from #7629. Reopening doesn't work, but inheriting may do. I have a use-case described in the mentioned issue.

enum Foo
  Bar
end

enum Qux < Foo
  Baz
end

pp Qux.values # => [Qux::Bar, Qux::Baz]

Also:

def handle(foo : Foo)
end

def handle(qux : Qux)
  if qux.bar?
    handle(qux.as(Foo)) # Maybe another syntax, but you get the idea
  else
    # ...
  end
end
Also

#6653 (though I still don't have a usecase for this 😆):

abstract enum Foo
  Bar
end

enum Qux < Foo
end

pp Qux.values # => [Qux::Bar]

enum Quux < Foo
  Baz
end

pp Quux.values # => [Quux::Bar, Quux::Baz]

def handle(foo : Foo)
  if foo.bar?
  end
end
@j8r
Copy link
Contributor

j8r commented Apr 5, 2019

I've found this related comment https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/types.cr#L2634
# enum Foo < Enum(Int32)

@jhass jhass changed the title Inheriting enums Support inheriting enums Nov 7, 2019
@straight-shoota
Copy link
Member

I don't see how the concept of inheritance fits with enums. Is there any good use case for this?

I'd suggest to close this.

@j8r
Copy link
Contributor

j8r commented Feb 5, 2022

There is still this TODO, what's planned about it?

@asterite
Copy link
Member

asterite commented Feb 5, 2022

That's an implementation detail.

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

No branches or pull requests

5 participants