using JET, AbstractTrees
struct S
c::Int
end
function AbstractTrees.children(s::S)
c = s.c
Iterators.map(Returns(S(c - 1)), Base.OneTo(c))
end
it = Leaves(S(3))
@report_opt collect(S, it) # ═════ 15 possible errors found ═════
it = PreOrderDFS(S(3))
@report_opt collect(S, it) # ═════ 9 possible errors found ═════
it = PostOrderDFS(S(3))
@report_opt collect(S, it) # ═════ 16 possible errors found ═════
For comparison, Base.Generator collects fine without run time dispatch:
using JET
struct S
c::Int
end
it = Iterators.map(S, 1:5)
@report_opt collect(S, it)