Overloading `getproperty` in a type-stable manner

Update!

using:

function Base.getproperty(m::ABM{A, S, F, P}, s::Symbol) where {A, S, F, P}
    if s === :agents
        return getfield(m, :agents)
    elseif s === :space
        return getfield(m, :space)
    elseif s === :scheduler
        return getfield(m, :scheduler)
    elseif s === :properties
        return getfield(m, :properties)
    elseif P <: Dict
        return getindex(getfield(m, :properties), s)
    else # properties is assumed to be a struct
        return getproperty(getfield(m, :properties), s)
    end
end

and restarting Julia to clear everything works, but one must be sure to test this inside functions so that constant propagation occurs!

@simeonschaub Hah I just saw your answer! You say the same thing!

1 Like