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
Can you check if #9634 fixes this? If not, something in #9585 is probably causing this regression.
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.
That is, you should either be doing yield or writing &block : String -> in both cases
That is, that the code compiles in 0.35.1 is actually a bug that is now "fixed".
@bcardiff #9634 doesn't fix this.
Thanks, @asterite for the explanation. &block : String -> is working for me.
Closing.
Let's keep this open because the error message is very confusing.
Most helpful comment
Let's keep this open because the error message is very confusing.