Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dirty macro warning + auto arity support #110

Merged
merged 11 commits into from
Feb 26, 2024
Merged
29 changes: 27 additions & 2 deletions lib/unifex/specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,40 @@ defmodule Unifex.Specs do

functions_docs = parse_docs(config, specs_file)

dirty_functions =
config
|> Keyword.get_values(:dirty_functions)
|> List.flatten()
|> Enum.flat_map(fn {dirty_func, type} ->
dirty_name =
case dirty_func do
{name, _arity} -> name
name -> name
end

{matched_name, matched_args} = List.keyfind(functions_args, dirty_name, 0, {nil, nil})

if matched_name != nil and matched_args != nil and
dirty_func in [matched_name, {matched_name, length(matched_args)}] do
Copy link
Contributor Author

@bartkrak bartkrak Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mat-hek I needed to add these nil checks to your suggestion, otherwise if List.keyfind() doesn't match length(matched_args) results in a crash

bartkrak marked this conversation as resolved.
Show resolved Hide resolved
[{{dirty_name, length(matched_args)}, type}]
else
Logger.warning(
"Function #{dirty_name} marked as dirty does not match any function defined in spec (#{specs_file})."
)

[]
end
end)
|> Map.new()

%__MODULE__{
name: name,
module: Keyword.get(config, :module),
functions_args: functions_args,
functions_results: functions_results,
functions_docs: functions_docs,
sends: Keyword.get_values(config, :sends),
dirty_functions:
config |> Keyword.get_values(:dirty_functions) |> List.flatten() |> Map.new(),
dirty_functions: dirty_functions,
callbacks: config |> Keyword.get_values(:callback) |> Map.new(),
interface: Keyword.get(config, :interface),
state_type: Keyword.get(config, :state_type, nil),
Expand Down