Skip to content

Commit

Permalink
Remove unused assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrimpyCat committed Aug 13, 2016
1 parent 2e3b405 commit 6bf6027
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tonic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ defmodule Tonic do
end

@doc false
defp mark_unused_variables({ :=, ctx, [variable|init] }, [assignment|unused]), do: { { :=, ctx, [underscore_variables(variable, assignment)|init] }, unused }
defp mark_unused_variables({ :=, ctx, [variable|init] }, [assignment|unused]) do
used = Enum.reduce(assignment, false, fn
{ _, used }, false -> used
_, _ -> true
end)
{ if(used, do: { :=, ctx, [underscore_variables(variable, assignment)|init] }, else: nil), unused }
end
defp mark_unused_variables({ :__block__, ctx, ops }, unused) do
{ ops, unused } = Enum.map_reduce(ops, unused, &mark_unused_variables/2)
{ { :__block__, ctx, ops }, unused }
Expand Down

0 comments on commit 6bf6027

Please sign in to comment.