# Confusing error output \`instance variable @x of A was inferred to be Nil\`

**URL:** <https://forum.crystal-lang.org/t/confusing-error-output-instance-variable-x-of-a-was-inferred-to-be-nil/5053>\
**Category:** Help & Support\
**Created:** [November 1, 2022, 4:18am UTC](https://forum.crystal-lang.org/t/confusing-error-output-instance-variable-x-of-a-was-inferred-to-be-nil/5053 "2022-11-01T04:18:21Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [November 1, 2022, 2:29pm UTC](https://forum.crystal-lang.org/t/confusing-error-output-instance-variable-x-of-a-was-inferred-to-be-nil/5053/4 "2022-11-01T14:29:46Z")

</div>

Because when the compiler sees:

```crystal
@var = some_expression

```

the compiler will try to infer the type from `some_expression`. In this case it’s this:

```crystal
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. The compiler doesn’t look at calls to infer the type of instance vars: just what you assign to `@x` inside the constructor (or, well, any other method, but never calls to methods.)

---

_[View the full topic](https://forum.crystal-lang.org/t/confusing-error-output-instance-variable-x-of-a-was-inferred-to-be-nil/5053)._
