# Type inference use the default value of argument not work?

**URL:** https://forum.crystal-lang.org/t/type-inference-use-the-default-value-of-argument-not-work/7372
**Category:** Help & Support
**Created:** [November 1, 2024, 9:50am UTC](https://forum.crystal-lang.org/t/type-inference-use-the-default-value-of-argument-not-work/7372 "2024-11-01T09:50:30Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)
#### Post date: [November 1, 2024, 12:02pm UTC](https://forum.crystal-lang.org/t/type-inference-use-the-default-value-of-argument-not-work/7372/3 "2024-11-01T12:02:05Z")

</div>

Thanks for explain.

But, i still remember asterite said, ` The compiler doesn’t look at calls to infer the type of instance vars`, i found the following link.

> [@Confusing error output \`instance variable @x of A was inferred to be Nil\`](https://forum.crystal-lang.org/t/confusing-error-output-instance-variable-x-of-a-was-inferred-to-be-nil/5053/4):
>
> Because when the compiler sees: @var = some\_expression the compiler will try to infer the type from some\_expression. In this case it’s this: x || nil Can we infer something from x? Let’s look if it has a type restriction. Nope, it doesn’t have any. Can we infer something from nil? Yes! It’s nil so it must be of type Nil. Well, Nil or something else (x) that we don’t know the type of. So the end result is that we can only infer it to be Nil. It doesn’t matter what you pass to the constructor…

So, why this happen for a local variable? (value treat as a local variable, right?)

---

_[View the full topic](https://forum.crystal-lang.org/t/type-inference-use-the-default-value-of-argument-not-work/7372)._
