Open kostya opened 5 years ago
Another case that hints that abstract methods in this language should maybe disappear
The same will happen for any macro that expands a method. They might need a way to inject the return type in order to comply with the current abstract method check.
A way to unlock the delegate macro is to allow passing the returning type.
delegate :bla, to: @bla, returning: Int32
delegate bla : Int32, to: @bla
# NOTE: proposal / not working example
But it takes some of the fun.
The property macro does allow return types already.
As I mentioned at https://github.com/crystal-lang/crystal/issues/8232#issuecomment-535115398 if the check is reframed as an after check to enforce that the contract of the abstract method is hold then this issue could be resolved without changes to the delegate macro.
Maybe an after check could work. The problem is that when I tried to do that the compiler would already complain of the type mismatch in the regular type inference phase, or complain about the missing method. In summary, the compiler will complain, it's just that the error message will be slightly different.
I understand that the compiler will probably complain before a delayed abstract check. If the offending override is used in a way it bothers. The explicit return type helped to catch this earlier.
Maybe the relaxation is that if there is an explicit return type it needs to match the abstract def. That way the generated method that will probably work by construction will not need a workaround to annotate a return type.
A compiler tool could be in charge of suggesting the explicit return types.
(throwing ideas to find the sweet spot of freedom and contracts here)
is this ok?