# Some thoughts for Crystal arguments default value and type inference

**URL:** <https://forum.crystal-lang.org/t/some-thoughts-for-crystal-arguments-default-value-and-type-inference/5045>\
**Category:** Help & Support\
**Created:** [October 29, 2022, 7:11pm UTC](https://forum.crystal-lang.org/t/some-thoughts-for-crystal-arguments-default-value-and-type-inference/5045 "2022-10-29T19:11:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 29, 2022, 7:46pm UTC](https://forum.crystal-lang.org/t/some-thoughts-for-crystal-arguments-default-value-and-type-inference/5045/2 "2022-10-29T19:46:47Z")

</div>

> [@zw963](#):
>
> It should work, right? because `@option` can never by nil, but still get compile error:

That’s precisely the problem, `@option` isn’t nilable, but you’re allowed to pass a `nil` argument to the constructor. This in turn changes the error from “no overload” to what you see there because you’re trying to assign a variable that can be nilable to an ivar that cannot.

In this case, I’d do something like:

```auto
def initialize(option : YAML::Any? = nil)
  @option = option || YAML.parse("{}")
end

```

Related: [[RFC] Undefined Type](https://forum.crystal-lang.org/t/rfc-undefined-type/2695)

---

_[View the full topic](https://forum.crystal-lang.org/t/some-thoughts-for-crystal-arguments-default-value-and-type-inference/5045)._
