Unknown type ranch:ref/0 dialyzer warning in cowboy_req on Erlang/OTP 26

Hello, I’m seeing 2 new dialyzer warnings in my app that uses cowboy on 26.0 that weren’t there on 25.3:

Line 134 Column 9: Unknown type ranch:ref/0
Line 152 Column 18: Unknown type ranch_proxy_header:proxy_info/0

It’s using cowboy 2.10.0 which I believe uses ranch 1.8.0. In the case of ranch:ref/0 I can indeed see that cowboy_req references ranch:ref/0 and ranch defines and exports it. So shouldn’t it keep working?

Has anyone seen and resolved the issue?

Here’s a run with the issue Remove rinseweb_wiz:answer/1 which should no longer be used · RinseOne/rinseweb@f706757 · GitHub

Digging further into this, I see that with the Erlang/OTP 26 a new version of Dialyzer 5.1 was released. According to its release notes a backward incompatible change was introduced to enable unknown option by default.

Dialyzer has enabled (by default) warnings about unknown types and functions.

Prior to this change, Dialyzer had warnings about unknown types and functions disabled (by default).

This default value has been overwritten; Dialyzer now warns about unknown types and functions (as requested by the community in GH-5695).

So it seems like the options are

  1. Add Dialyzer option no_unknown to the project to disable the unknown types and functions checks to restore previous behavior.
  2. Manually add problematic dependencies that aren’t automatically included in the PLT such as {plt_extra_apps, [ranch]}.
  3. Add Dialyzer option {plt_apps, all_deps} to the project.

I would like to take advantage of the new default, so I’m not inclined to do (1), but it’s interesting that the default behavior was changed that might seemingly result in violation of the principle of the least astonishment.

So, assuming the above assessment is correct, is (2) or (3) or another I don’t know about the recommended path forward?

1 Like

Assuming you want as much automatic checking as possible, I’d say your options are (2) and:

(4) Add missing type definitions and/or exports where needed.

I recently had the exact same issue you reported here, except with use of file:position/0 which is documented but wasn’t exported for unclear reasons. I ended up submitting a PR to fix that (file: export location/0 type by mikpe · Pull Request #7486 · erlang/otp · GitHub).

1 Like

Thanks for the reply. In this case, the type definitions and exports are already there, as I linked them in the original post. The problem seems to be that Dialyzer doesn’t seem to know which apps need to be in the PLT (2nd level dependencies?) and their absence is exposed via the warnings produced due to making the unknown check on by default. In fact, I’m actually not sure why I only see the 2 warnings I reported and not many many more. Part of me suspects there’s a subtle bug somewhere but :person_shrugging:.

I’m also inclined to go with option (2) just because, at least in my case, the project is small enough that I can take it on case by case basis, and option (3) makes the check take noticeably, like 7x, longer time.