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

Created on 23 Sep 2020  路  6Comments  路  Source: crystal-lang/crystal

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
compiler

Most helpful comment

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

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oprypin picture oprypin  路  3Comments

Sija picture Sija  路  3Comments

cjgajard picture cjgajard  路  3Comments

asterite picture asterite  路  3Comments

jhass picture jhass  路  3Comments