# Accessing the field of \`Pair\` seems to be type-unstable

**URL:** <https://discourse.julialang.org/t/accessing-the-field-of-pair-seems-to-be-type-unstable/78045>\
**Category:** General Usage\
**Tags:** type-stability\
**Created:** [March 17, 2022, 6:12pm UTC](https://discourse.julialang.org/t/accessing-the-field-of-pair-seems-to-be-type-unstable/78045 "2022-03-17T18:12:25Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 17, 2022, 6:30pm UTC](https://discourse.julialang.org/t/accessing-the-field-of-pair-seems-to-be-type-unstable/78045/4 "2022-03-17T18:30:29Z")

</div>

To elaborate, `@code_warntype` only sees the _types_ of the arguments to the function call you give it.  
The syntax `p1.first` is just a shorthand for `getproperty(p1, :first)`, so when you do: `@code_warntype p1.first`, you’re seeing the result of:

```julia
code_warntype(getproperty, (typeof(p1), typeof(:first)))

```

or, in other words:

```julia
code_warntype(getproperty, (Pair{Symbol, Int}, Symbol))

```

which isn’t enough information to indicate whether you’re accessing the first or second element.

Putting the access into a function lets Julia’s usual constant propagation machinery do its work, and `@code_warntype` can correctly show you that result when you use it on the new function.

---

_[View the full topic](https://discourse.julialang.org/t/accessing-the-field-of-pair-seems-to-be-type-unstable/78045)._
