Infer functions fail to typecheck (functions don't exist)
smaximov opened this issue · comments
Consider the following minimal example (or see the repo):
defmodule InferTypecheckIssue do
def get(binary), do: Infer.get(binary)
def get_from_path(path), do: Infer.get_from_path(path)
end
When running dialyzer
(via dialyxir
v1.4.2), it fails with errors:
$ mix dialyzer
[...snip...]
Total errors: 2, Skipped: 0, Unnecessary Skips: 0
done in 0m0.69s
lib/infer_typecheck_issue.ex:2:unknown_function
Function Infer.get/1 does not exist.
________________________________________________________________________________
lib/infer_typecheck_issue.ex:3:unknown_function
Function Infer.get_from_path/1 does not exist.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2
I must admit I have no idea why it happens. I thought that it has something to do with the infer's project config, so I looked at mix.exs
but didn't find anything suspicious.
Upon further inspection, seems like this line is the culprit:
Line 14 in 65beb86
It breaks dialyzer's analysis:
:dialyzer.run error: Analysis failed with error:
Unable to find type 'fun'/1
This breakage in turn results in dialyzer not finding any function (or callback info for builtin and 3rd-party library behaviours); here's is excerpt of dialyzer's output from our application:
Total errors: 3082, Skipped: 69, Unnecessary Skips: 0
done in 0m7.0s
deps/mox/lib/mox.ex:476:unknown_function
Function Mox.__dispatch__/4 does not exist.
________________________________________________________________________________
lib/application.ex:17:unknown_function
Function :telemetry.attach/4 does not exist.
________________________________________________________________________________
lib/binomo/application.ex:14:unknown_function
Function Logger.__do_log__/4 does not exist.
________________________________________________________________________________
lib/binomo/application.ex:14:unknown_function
Function Logger.__should_log__/2 does not exist.
________________________________________________________________________________
lib/binomo/application.ex:25:unknown_function
Function :telemetry.attach_many/4 does not exist.
________________________________________________________________________________
lib/oban/worker.ex:1:callback_info_missing
Callback info about the Oban.Worker behaviour is not available.
________________________________________________________________________________
lib/phoenix/endpoint.ex:1:callback_info_missing
Callback info about the Plug behaviour is not available.
________________________________________________________________________________
lib/phoenix/endpoint.ex:1:callback_info_missing
Callback info about the Phoenix.Endpoint behaviour is not available.
________________________________________________________________________________
[...snip...]
Success typing should be:
@type matcher_fun() :: (binary() -> boolean())
@smaximov thank you for looking into this. I will prepare a PR and merge it ASAP! 🤝
Closed in #12