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

Error: abstract def must be implemented for methods with block argument #9771

Open
mamantoha opened this issue Sep 23, 2020 · 6 comments
Open

Comments

@mamantoha
Copy link
Contributor

Hi there.

This code works with Crystal 0.35.1

abstract class Base
  abstract def with_type(type : String = "default", &block)
end

class Adapter < Base
  def with_type(type : String = "default", &block)
    yield type
  end
end

adapter = Adapter.new
adapter.with_type("string") do |type|
  puts type
end

But on Crystal nightly is not compiled:

 2 | abstract def with_type(type : String = "default", &block)
                  ^--------
Error: abstract `def Base#with_type(type : String = "default", &block)` must be implemented by Adapter
@bcardiff
Copy link
Member

Can you check if #9634 fixes this? If not, something in #9585 is probably causing this regression.

@asterite
Copy link
Member

Note that yield type is making the block accept an argument, but the original method doesn't have block arguments. The message should probably mention this, but the compiler is working fine.

@asterite
Copy link
Member

That is, you should either be doing yield or writing &block : String -> in both cases

@asterite
Copy link
Member

That is, that the code compiles in 0.35.1 is actually a bug that is now "fixed".

@mamantoha
Copy link
Contributor Author

@bcardiff #9634 doesn't fix this.

Thanks, @asterite for the explanation. &block : String -> is working for me.
Closing.

@asterite asterite reopened this Sep 23, 2020
@asterite
Copy link
Member

Let's keep this open because the error message is very confusing.

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

No branches or pull requests

3 participants