# Type inferrence limitation?

**URL:** <https://forum.crystal-lang.org/t/type-inferrence-limitation/5598>\
**Category:** Help & Support\
**Created:** [April 23, 2023, 5:59pm UTC](https://forum.crystal-lang.org/t/type-inferrence-limitation/5598 "2023-04-23T17:59:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [April 23, 2023, 5:59pm UTC](https://forum.crystal-lang.org/t/type-inferrence-limitation/5598/1 "2023-04-23T17:59:29Z")

</div>

Why does this work:

```auto
mail = user.mail # Type is String?

if mail
  env.session.string("user_mail", mail) # Only takes String

```

And this not?

```auto
if user.mail
  env.session.string("user_mail", user.mail)

```

I would assume they’re the same.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 23, 2023, 6:13pm UTC](https://forum.crystal-lang.org/t/type-inferrence-limitation/5598/2 "2023-04-23T18:13:23Z")

</div>

[https://crystal-lang.org/reference/1.8/syntax\_and\_semantics/if\_var.html#method-calls](https://crystal-lang.org/reference/1.8/syntax_and_semantics/if_var.html#method-calls)

tl;dr Procs and methods aren’t guaranteed to return the same more-specific type on two successive calls.

---

<div class="post-metadata">

**Author:** ![Xen](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/xen/32/2288_2.png) [@Xen](https://forum.crystal-lang.org/u/Xen)\
**Post date:** [April 23, 2023, 6:42pm UTC](https://forum.crystal-lang.org/t/type-inferrence-limitation/5598/3 "2023-04-23T18:42:38Z")

</div>

Aha… Well, in theory the compiler could notice that `user.mail` is a simple getter that returns the same insta… Oooh, and the point on why it doesn’t work on instance vars applies…

Makes sense.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 23, 2023, 7:02pm UTC](https://forum.crystal-lang.org/t/type-inferrence-limitation/5598/4 "2023-04-23T19:02:33Z")

</div>

Yea, otherwise would technically be possible with concurrency to switch to another fiber that mutates the ivar after the initial check that then could cause issues.
