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

Surprising error with generic abstract base class #3349

Closed
rf- opened this issue Sep 25, 2016 · 5 comments
Closed

Surprising error with generic abstract base class #3349

rf- opened this issue Sep 25, 2016 · 5 comments

Comments

@rf-
Copy link

rf- commented Sep 25, 2016

When I try to compile the following code:

abstract class Base(Options)
  abstract def run(opts : Options)
end

class SpecificOptions
end

class Derived < Base(SpecificOptions)
  def run(opts : SpecificOptions)
  end
end

Derived.new.run(SpecificOptions.new)

I get this error:

Error in line 2: abstract `def Base(Options)#run(opts : Options)` must be implemented by Derived

I would have expected this to work, but maybe I'm misunderstanding something about the syntax?

@rf-
Copy link
Author

rf- commented Sep 25, 2016

@RayDF pointed out on Gitter that removing the abstract keyword fixes the problem. I made a more fleshed-out example to prove to myself that polymorphism actually works correctly with the non-abstract version: https://play.crystal-lang.org/#/r/1aqj

@asterite
Copy link
Member

Yes, right now the abstract check is pretty simple, it doesn't resolve generic type arguments, but the above should probably work. Workaround to make it work for now: remove the abstract method definition.

@hanyuone
Copy link

hanyuone commented May 3, 2018

Bump to this issue: has there been any attempt to fix this so far?

@asterite
Copy link
Member

asterite commented May 3, 2018

@Qwerp-Derp No, and it won't happen anytime soon.

@straight-shoota
Copy link
Member

Fixed. The original example compiles with 0.35.1.

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

4 participants