julia> struct S
x
end
julia> function Base.getproperty(x::S, sym::Symbol)
if sym == :a
"a"
else
# fallback to getfield
getfield(x, sym)
end
end
julia> obj = S(1)
S(1)
julia> obj.a
"a"
julia> obj.x
1
julia> obj.y
ERROR: type S has no field y
Stacktrace:
[1] getproperty(::S, ::Symbol) at ./REPL[2]:6
4 Likes