Tanks!
I tried following the code in this simple case,
using Flatten
struct Foo{A,B,C}
a::A
b::B
c::C
end
nested = Foo(Foo(1, 2, 3), 4.0, 5.0)
#Foo{Foo{Int64,Int64,Int64},Float64,Float64}(Foo{Int64,Int64,Int64}(1, 2, 3), 4.0, 5.0)
flatten(nested)
#(1, 2, 3, 4.0, 5.0)
using the debugger in vscode, but when executing the function _flatten(x, ft, use, ignore) #line 132
everything crashes with the following error
┌ Error: Some Julia code in the VS Code extension crashed
└ @ VSCodeDebugger c:\Users\sprmn\.vscode\extensions\julialang.language-julia-1.38.2\scripts\error_handler.jl:15
ERROR: Method is @generated; try `code_lowered` instead.
Stacktrace:
[1] error(s::String)
...
cursor stops at line 110 flatten_builder(T, fname) = quote
I assume the sequence is:
_flatten(x, ft, use, ignore)
#then
@generated _flatten(obj, flattentrait, use, ignore) = flatten_inner(obj)
#then
flatten_inner(T) = nested(T, flatten_builder, flatten_combiner)
#then
flatten_builder(T, fname) = quote
if flattentrait($T, Val{$(QuoteNode(fname))})
flatten(getfield(obj, $(QuoteNode(fname))), flattentrait, use, ignore)
else
()
end
end
but i’m not sure i understand, because the code is too complex for me, especially for the parts where metaprogramming is used.
Would it help me to understand something more if you could explain in a simple way, referring to the tested example, what function they have and what values they assume, the flattentrait, flatten_builder and flatten_combiner variables?
If it was this expression that causes problems for the debugger, how can I replace it with another equivalent but digestible by the debugger?
@generated _flatten(obj, flattentrait, use, ignore) = flatten_inner(obj)