Skip to content

Commit

Permalink
Normalization & Truncation Error Fixes (#146)
Browse files Browse the repository at this point in the history
* added normalization edge case for tuples
* Use trunc when idx is given as a float instead of an int

---------

Co-authored-by: dt <[email protected]>
  • Loading branch information
houllette and realcorvus authored Dec 7, 2023
1 parent 7eb76c1 commit 052d1e0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/sobelow/parse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,17 @@ defmodule Sobelow.Parse do
{finding, List.flatten(opts)}
end

# This handles normalizations for the case where the finding is a dot-access tuple
def normalize_finding({finding, {:., _, [{var, _, _}, field]}}) when is_atom(field) do
{finding, "#{atom_to_string(var)}.${atom_to_string(field)}"}
end

def normalize_finding({finding, opt}) do
{finding, [opt]}
end

defp atom_to_string(atom) when is_atom(atom), do: Atom.to_string(atom)

def get_erlang_funs_of_type(ast, type) do
{_, acc} = Macro.prewalk(ast, [], &get_erlang_funs_of_type(&1, &2, type, :erlang))
acc
Expand Down Expand Up @@ -455,7 +462,7 @@ defmodule Sobelow.Parse do
end

defp create_fun_cap(fun, meta, idx) when is_number(idx) do
opts = Enum.map(1..idx, fn i -> {:&, [], [i]} end)
opts = Enum.map(1..trunc(idx), fn i -> {:&, [], [i]} end)
{fun, meta, opts}
end

Expand Down

0 comments on commit 052d1e0

Please sign in to comment.