The problem is that your getproperty
is recursive since v.x
and v.y
from inside the body will also result in a call to getproperty
. Recursion isn’t necessarily (or even usually) a problem for inference, but there’s various heuristic limits on how hard inference tries to go through the recursion, made more complicated here by the fact that there’s also constant propagation needed to get the right answer. A more expert than me could probably tell you the details, but I think its basically just hitting those limits.
The reason :yx
works is because the return value in that case is Vec2(...)
, so it doesn’t matter what’s in the ...
, the compiler knows the answer can only be a Vec2
, which is a concrete type.
The solution for :tuple
is just to use getfield
instead and skip the recursion, e.g. this works:
if name == :tuple
(getfield(v,:x), getfield(v,:y))