nested_dict.exs
defmodule Customer do
defstruct name: "", company: ""
end
defmodule BugReport do
defstruct owner: %Customer{}, details: "", severity: 1
end
I got this error after writing this in iex
iex(1)> c "nested_dict.exs"
error: Customer.__struct__/1 is undefined, cannot expand struct Customer. Make sure the struct name is correct. If the struct name exists and is
correct but it still cannot be found, you likely have cyclic module usage in your code
β
4 β owner: %Customer{name: "Dave", company: "PragProg"},
β ^
β
ββ nested_dict.exs:4:10
I also try running it using elixir nested_dict.exs
got the same error.
I again also run them in through different file:
Customer.exs
defmodule Customer do
defstruct name: "", company: ""
end
nested_dict_api.exs
Code.require_file("Customer.exs")
defmodule BugReport do
defstruct owner: %Customer{}, details: ""
end
nested_dict.exs
Code.require_file("nested_dict_api.exs")
report = %BugReport{
owner: %Customer{name: "Dave", company: "PragProg"},
details: "broken"
}
IO.inspect(report)
Again, the same error ,
I am pretty sure that there are no typo in my code as fas as i know
Can someone please tell me whatβs wrong in my code and how to solve it ?
Thank you,
Elixir : 1.17.0 (compiled with Erlang/OTP 27)
OS : Linux Mint 21