Unexpected REPL display issues after overloading

Is it intentional that defining getproperty(::Type{MyType}, ...) appears to interfere with REPL display and introspection of the type itself, even when unknown properties are delegated to getfield?

struct V{P} end

function Base.getproperty(T::Type{V{P}}, sym::Symbol) where P
    if sym == :foo
        return n -> n * P
    else
        getfield(V{P}, sym)
    end
end

V{5}

The type itself appears to be perfectly usable. Assignment, property access, and callable-type behavior all work correctly:

T = V{5}; 
T.foo(7)
T.name

Interestingly, the issue does not seem to affect the type’s functionality. It only surfaces when the REPL attempts to display the type.

Since the custom property works and unknown properties are forwarded to getfield, I am wondering whether this behavior is intentional or whether it might be a corner case in the REPL display machinery.

Hi, and welcome to the Julia community!


This doesn’t really get to the heart of your question, but let me point out that if you delegate using T instead of V{P} everything seems fine:

julia> struct V{P} end

julia> function Base.getproperty(T::Type{V{P}}, sym::Symbol) where P
           if sym == :foo
               return n -> n * P
           else
               getfield(T, sym)
           end
       end

julia> V{5}
V{5}