Skip to content

Commit c6b2177

Browse files
author
Vadim Tsvetkov
committed
Check if new/0 is defined inside macro
1 parent ae05f35 commit c6b2177

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/algae/internal.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,22 @@ defmodule Algae.Internal do
251251
def default_value({{:., _, [String, :t]}, _, _}), do: ""
252252

253253
def default_value({{:., _, [{_, _, adt}, :t]}, _, []}) do
254-
if Kernel.function_exported?(Module.concat(adt), :new, 0) do
255-
quote do: unquote(Module.concat(adt)).new()
256-
else
257-
quote do: nil
254+
quote do
255+
if Kernel.function_exported?(unquote(Module.concat(adt)), :new, 0) do
256+
unquote(Module.concat(adt)).new()
257+
else
258+
nil
259+
end
258260
end
259261
end
260262

261263
def default_value({{:., _, [module, :t]}, _, []}) do
262-
if Kernel.function_exported?(module, :new, 0) do
263-
quote do: unquote(module).new()
264-
else
265-
quote do: nil
264+
quote do
265+
if Kernel.function_exported?(unquote(module), :new, 0) do
266+
unquote(module).new()
267+
else
268+
nil
269+
end
266270
end
267271
end
268272

0 commit comments

Comments
 (0)