julia> @generated f(obj) = :(string($((:(getfield(obj, $i)) for i in 1:fieldcount(obj))...)))
f (generic function with 1 method)
julia> f(1im)
"01"
julia> f((1, 2, 2.4))
"122.4"
julia> @code_warntype f(1im)
Variables:
#self# <optimized out>
obj::Complex{Int64}
Body:
begin
#= REPL[4]:1 =#
# meta: location REPL[4] @generated body
return $(Expr(:invoke, MethodInstance for #print_to_string#245(::Void, ::Function, ::Int64, ::Vararg{Int64,N} where N), :(Base.#print_to_string#245), :($(QuoteNode(nothing))), :($(QuoteNode(Base.print_to_string))), :((Main.getfield)(obj, 1)::Int64), :((Main.getfield)(obj, 2)::Int64)))::String
# meta: pop location
end::String
julia> @code_warntype f((1, 2, "", 3))
Variables:
#self# <optimized out>
obj::Tuple{Int64,Int64,String,Int64}
Body:
begin
#= REPL[4]:1 =#
# meta: location REPL[4] @generated body
return $(Expr(:invoke, MethodInstance for #print_to_string#245(::Void, ::Function, ::Int64, ::Vararg{Any,N} where N), :(Base.#print_to_string#245), :($(QuoteNode(nothing))), :($(QuoteNode(Base.print_to_string))), :((Main.getfield)(obj, 1)::Int64), :((Main.getfield)(obj, 2)::Int64), :((Main.getfield)(obj, 3)::String), :((Main.getfield)(obj, 4)::Int64)))::String
# meta: pop location
end::String
?