# Nested modules with the same name

**URL:** <https://forum.elixirforum.com/t/nested-modules-with-the-same-name/6145>\
**Category:** Questions\
**Created:** [June 17, 2017, 5:27pm UTC](https://forum.elixirforum.com/t/nested-modules-with-the-same-name/6145 "2017-06-17T17:27:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sohopro](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@sohopro](https://forum.elixirforum.com/u/sohopro)\
**Post date:** [June 17, 2017, 5:27pm UTC](https://forum.elixirforum.com/t/nested-modules-with-the-same-name/6145/1 "2017-06-17T17:27:08Z")

</div>

```elixir
defmodule Foo do
  def func1 do
  end
  def func2 do
    func1
  end
end
Foo.func2

```

The above works.

```elixir
defmodule Foo do
  def func1 do
  end
  def func2 do
    Foo.func1
  end
end
Foo.func2

```

Works too.

But if add an inner module with same name like:

```elixir
defmodule Foo do
  defmodule Foo do
  end
  def func1 do
  end
  def func2 do
    Foo.func1
  end
end
Foo.func2

```

Does not work.

Is there reason to allow a code like the second example?  
It seems strange in a module that module’s name means that module .  
I think it’s risk of unexpected behavior.

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [June 19, 2017, 4:52pm UTC](https://forum.elixirforum.com/t/nested-modules-with-the-same-name/6145/2 "2017-06-19T16:52:39Z")

</div>

It is because when you `defmodule` a module `inside` of another module then it auto-aliases it as well. You only have this issue if the parent and child module names precisely match.

I’m of the opinion that no module should have the same name anywhere anyway, sub or not. 🙂
