Given the class definition below, I am faced with the following problem, which I am stuck on !
How can I define the each method so that iteration is done on @sources.
def each(& : T ->) : Nil
@sources.each do |v|
yield v
end
end
However when trying this I get Error: recursive block expansion: blocks that yield are always inlined, and this call leads to an infinite inlining, which I haven’t seen before . BUT, only if the initialize argument is typed as Enumerable(T), if i change that to like Array(T) it works fine…so not sure what’s going on there.
Yes, I have encountered this very problem, hence my call for help. Unfortunately, the Enumerable(T) restriction is the most suitable for my application, Array(T) would be too reductive.
Perhaps a lower level approach (pointers) is worth considering…
I presume the error comes from the fact that the definition of @sources.each is Enumerable(Int32)#each and its called from an implementation of Enumerable(Int32)#each (because include Enumerable(T) for Table(T)).
So you can nest Table indefinitely: Table(Int32).new(Table(Int32).new(Table(Int32).new(Table(Int32).new(...)))). This would lead to recursive calls of the same method, resulting in recursive block expansion.