Hi,
I’m having problems with inherited
macro, does it runs just once for a type hierarchy?
I want to define an inherited
macro in 2 classes in the hierarchy and have them run in the third class. To avoid the macro to run in the first 2 I use a annotation.
Example, C inherits B that inherits A, B and A has a macro inherited
, When C in born to the compiler I was expecting the inherited
macro defined in A
and then the inherited
macro defined in B
to run, but just the macro from A
really generates code. Weird is that if I introduce some syntax error in the code generated by the inherited
macro defined in type B
the compiler detects it, so it seems the macro is being executed but generating nothing? Is this a compiler bug or am I missing something?
annotation Skip
end
@[Skip]
class A
macro inherited
{% unless @type.annotation(Skip) %}
def foo
puts "A"
end
{% end %}
end
end
@[Skip]
class B < A
macro inherited
{% unless @type.annotation(Skip) %}
def foo
previous_def
puts "B"
end
{% end %}
end
end
class C < B
end
C.new.foo
I was expecting this to print:
A
B
But it just prints
A
Why I want this? I have a type annotation defined in one shard that generated some stuff, but in another shard I want to extend this annotation with more parameters that add more stuff in a series of functions defined with previous_def
calls. yes, GTK stuff