Works for me:
$ iex
Erlang/OTP 22 [erts-10.7] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.10.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule RootModule do
...(1)> defmodule SubModule do
...(1)> defstruct [:foo, :bar]
...(1)>
...(1)> @spec new() :: %__MODULE__{}
...(1)> def new() do
...(1)> %__MODULE__{}
...(1)> end
...(1)> end
...(1)> end
iex(2)> RootModule.SubModule.new
%RootModule.SubModule{bar: nil, foo: nil}
What versions of erlang and elixir are you using?


















