Skip to content

Commit

Permalink
Mark vars in codegen as generated to prevent warnings for __meta__
Browse files Browse the repository at this point in the history
Closes #41
  • Loading branch information
michalmuskala committed Jul 2, 2018
1 parent 1c93d91 commit 88dd85c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end
defimpl Jason.Encoder, for: Any do
defmacro __deriving__(module, struct, opts) do
fields = fields_to_encode(struct, opts)
kv = Enum.map(fields, &{&1, Macro.var(&1, __MODULE__)})
kv = Enum.map(fields, &{&1, generated_var(&1, __MODULE__)})
escape = quote(do: escape)
encode_map = quote(do: encode_map)
encode_args = [escape, encode_map]
Expand All @@ -94,6 +94,11 @@ defimpl Jason.Encoder, for: Any do
end
end

# The same as Macro.var/2 except it sets generated: true
defp generated_var(name, context) do
{name, [generated: true], context}
end

def encode(%_{} = struct, _opts) do
raise Protocol.UndefinedError,
protocol: @protocol,
Expand Down
7 changes: 6 additions & 1 deletion lib/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Jason.Helpers do
"""
defmacro json_map_take(map, take) do
take = Macro.expand(take, __CALLER__)
kv = Enum.map(take, &{&1, Macro.var(&1, Codegen)})
kv = Enum.map(take, &{&1, generated_var(&1, Codegen)})
escape = quote(do: escape)
encode_map = quote(do: encode_map)
encode_args = [escape, encode_map]
Expand All @@ -82,4 +82,9 @@ defmodule Jason.Helpers do
end
end
end

# The same as Macro.var/2 except it sets generated: true
defp generated_var(name, context) do
{name, [generated: true], context}
end
end

0 comments on commit 88dd85c

Please sign in to comment.