# Type Inference Problem with \`getproperty\`

**URL:** <https://discourse.julialang.org/t/type-inference-problem-with-getproperty/54585>\
**Category:** Performance\
**Created:** [February 4, 2021, 3:14am UTC](https://discourse.julialang.org/t/type-inference-problem-with-getproperty/54585 "2021-02-04T03:14:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 4, 2021, 3:31am UTC](https://discourse.julialang.org/t/type-inference-problem-with-getproperty/54585/2 "2021-02-04T03:31:16Z")

</div>

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:

```julia
	if name == :tuple
		(getfield(v,:x), getfield(v,:y))

```

---

_[View the full topic](https://discourse.julialang.org/t/type-inference-problem-with-getproperty/54585)._
