Define instance method with "macro inherited" in Crystal 0.21.1 -
as understand type declaration works kind_of
…
“so types aren't strictly type named rather act
is_a?
orkind_of?
.” https://github.com/crystal-lang/crystal/issues/4232
so think part of code works.
but when use macro define instance method on inherited class error message complains method missing wrong object.
class base macro inherited def name "joe smith" end end end class context < base; end class render def initialize(@inner_context : base); end def display name end forward_missing_to inner_context private property inner_context end puts render.new(context.new).display
and output is:
error in line 23: instantiating 'render#display()' in line 15: instantiating 'name()' in macro 'forward_missing_to' /usr/lib/crystal/object.cr:1132, line 1: > 1. macro method_missing(call) 2. inner_context.{{call}} 3. end 4. expanding macro in macro 'method_missing' expanded macro: forward_missing_to:1, line 1: > 1. inner_context.name 2. undefined method 'name' base (compile-time type base+)
what missing here?
@inner_context
of type base
, doesn't define base
method.
one solution mark base
abstract: abstract class base
.
Comments
Post a Comment