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

Infer functions fail to typecheck (functions don't exist) #11

Closed
smaximov opened this issue Nov 16, 2023 · 3 comments
Closed

Infer functions fail to typecheck (functions don't exist) #11

smaximov opened this issue Nov 16, 2023 · 3 comments

Comments

@smaximov
Copy link

smaximov commented Nov 16, 2023

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.

@smaximov
Copy link
Author

Upon further inspection, seems like this line is the culprit:

@type matcher_fun() :: fun((binary() -> boolean()))

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())

@daskycodes
Copy link
Owner

@smaximov thank you for looking into this. I will prepare a PR and merge it ASAP! 🤝

@daskycodes
Copy link
Owner

Closed in #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants