# Recursive typed literal hash won't compile

**URL:** <https://forum.crystal-lang.org/t/recursive-typed-literal-hash-wont-compile/2689>\
**Category:** Help & Support\
**Created:** [November 19, 2020, 10:41pm UTC](https://forum.crystal-lang.org/t/recursive-typed-literal-hash-wont-compile/2689 "2020-11-19T22:41:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrucePerens](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bruceperens/32/852_2.png) [@BrucePerens](https://forum.crystal-lang.org/u/BrucePerens)\
**Post date:** [November 19, 2020, 10:41pm UTC](https://forum.crystal-lang.org/t/recursive-typed-literal-hash-wont-compile/2689/1 "2020-11-19T22:41:47Z")

</div>

How can I declare a literal hash like this and have it compile? This won’t work:

```crystal
alias Allowed = Hash(Symbol, Allowed|Bool)
h = {
  :symbol => { :symbol => true } of Symbol => Allowed|Bool
} of Symbol => Allowed|Bool

```

The compiler says:

```auto
crystal build foo.cr
Showing last frame. Use --error-trace for full trace.

In /usr/share/crystal/src/hash.cr:1920:46

 1920 | def initialize(@hash : UInt32, @key : K, @value : V)
                                                 ^-----
Error: instance variable '@value' of Hash::Entry(Symbol, Bool | Hash(Symbol, Allowed | Bool)) must be (Bool | Hash(Symbol, Allowed | Bool)), not Hash(Symbol, Bool | Hash(Symbol, Allowed | Bool))

```

I can use a NamedTuple literal instead, I’m wondering if the above is just a compiler issue or if I’m doing something wrong.

---

<div class="post-metadata">

**Author:** ![nolyoi](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nolyoi](https://forum.crystal-lang.org/u/nolyoi)\
**Post date:** [November 24, 2020, 12:38am UTC](https://forum.crystal-lang.org/t/recursive-typed-literal-hash-wont-compile/2689/2 "2020-11-24T00:38:07Z")

</div>

> [@BrucePerens](#):
>
> ```auto
> h = {
> :symbol => { :symbol => true } of Symbol => Allowed|Bool
> } of Symbol => Allowed|Bool
> 
> ```

Why the `of Symbol => Allowed|Bool` on the main hash? It works with the following below:

```
alias Allowed = Hash(Symbol, Allowed|Bool)
h = {
  :symbol => { :symbol => true } of Symbol => Allowed|Bool
  } 
 
pp h #> {:symbol => {:symbol => true}}
pp typeof(h) #> Hash(Symbol, Hash(Symbol, Bool | Hash(Symbol, Allowed | Bool)))

```

The reason your example isnt working is because youre returning a `Hash(Symbol, Hash(Symbol, Bool))` not what youre defining in the Alias.

You could do this too:

```
alias Allowed = Hash(Symbol, Bool)
h = {
  :symbol => { :symbol => true } of Symbol => Bool
  } of Symbol => Allowed
 
pp typeof(h) #> Hash(Symbol, Hash(Symbol, Bool))

```
