Thank you for the time you explain this, but I need to convert atom inside sub_field macro, and user just put an atom
Code:
defmodule TestNestedStruct do
use GuardedStruct
guardedstruct do
field(:title, String.t())
field(:subject, String.t())
sub_field(:oop, String.t(), enforce: true) do
field(:title, String.t())
field(:fam, String.t())
end
field(:site, String.t())
end
end
And
Error
error: MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop.__struct__/0 is undefined, cannot expand struct MishkaDeveloperToolsTest.GuardedStructTest.TestNestedStruct.Oop. 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
test/guarded_struct_test.exs:534: MishkaDeveloperToolsTest.GuardedStructTest."test nested macro field"/1
I think it just accept a Tuple for creating submodule
defmacro sub_field(name, type, opts \\ [], do: block) do
ast = register_struct(block, opts)
name =
name
|> Atom.to_string()
|> Macro.camelize()
|> String.to_atom()
module_name = Module.concat(Elixir, name)
quote do
defmodule unquote(module_name) do
unquote(ast)
end
end
end
If I put sub_field(Oop, String.t(), enforce: true) do, it works ![]()
I am improving my macro






















