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

OTP-26 dialyzer errors on reference to file:location() type #7485

Closed
mikpe opened this issue Jul 9, 2023 · 1 comment
Closed

OTP-26 dialyzer errors on reference to file:location() type #7485

mikpe opened this issue Jul 9, 2023 · 1 comment
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@mikpe
Copy link
Contributor

mikpe commented Jul 9, 2023

Describe the bug
I have a module which implements a wrapper around the kernel's file:position/2 function. The wrapper function takes a Location so it's -spec uses file:location(). This compiles cleanly with OTP-25 and older, but with OTP-26 dialyzer generates a hard error: "Unknown type file:location/0", causing the build to fail.

The type is both defined and used in the file module documentation (https://www.erlang.org/doc/man/file.html) so I would have assumed it to be exported, but inspection of file.erl shows that it isn't, and never has been. Why earlier versions of dialyzer didn't flag this I don't know, perhaps defaults have changed, but the result is still a regression.

To Reproduce

> rebar3 new lib mylib
> cd mylib
> cat >> src/mylib.erl
-export([foo/2]).
-spec foo(file:io_device(), file:location()) -> ok.
foo(IoDev, Loc) ->
  {ok, _} = file:position(IoDev, Loc),
  ok.
^D

Compile and dialyze with OTP-25.3.2.3:

> rebar3 do compile,dialyzer
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling mylib
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling mylib
===> Dialyzer starting, this may take a while...
===> Updating plt...
===> Resolving project files...
===> Updating base plt...
===> Resolving base files...
===> Checking 206 files in /home/mikpe/.cache/rebar3/rebar3_25.3.2.3_plt...
===> Copying /home/mikpe/.cache/rebar3/rebar3_25.3.2.3_plt to /tmp/mylib/_build/default/rebar3_25.3.2.3_plt...
===> Checking 206 files in _build/default/rebar3_25.3.2.3_plt...
===> Doing success typing analysis...
===> Resolving project warning files...
===> Analyzing 1 files with _build/default/rebar3_25.3.2.3_plt...
> echo $?
0

Compile and dialyze with OTP-26.0.2:

> rm -rf _build
> rebar3 do compile,dialyzer
===> Failed to restore /home/mikpe/.cache/rebar3/plugins/.rebar3/rebar_compiler_erl/source_apps.dag file. Discarding it.

===> Analyzing applications...
===> Compiling hex_core
===> Compiling verl
===> Compiling rebar3_hex
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling mylib
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling mylib
===> Dialyzer starting, this may take a while...
===> Updating plt...
===> Resolving project files...
===> Updating base plt...
===> Resolving base files...
===> Checking 211 files in /home/mikpe/.cache/rebar3/rebar3_26.0.2_plt...
===> Copying /home/mikpe/.cache/rebar3/rebar3_26.0.2_plt to /tmp/mylib/_build/default/rebar3_26.0.2_plt...
===> Checking 211 files in _build/default/rebar3_26.0.2_plt...
===> Doing success typing analysis...
===> Resolving project warning files...
===> Analyzing 1 files with _build/default/rebar3_26.0.2_plt...

src/mylib.erl
Line 5 Column 29: Unknown type file:location/0
===> Warnings written to _build/default/26.0.2.dialyzer_warnings
===> Warnings occurred running dialyzer: 1
> echo $?
1

Expected behavior
I expected building with OTP-26 to succeed without errors or warnings, preferably by having file.erl export the previously non-exported type.

Affected versions
OTP-26.0.2.

Additional context
n/a

@mikpe mikpe added the bug Issue is reported as a bug label Jul 9, 2023
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Jul 10, 2023
@garazdawi
Copy link
Contributor

The type is both defined and used in the file module documentation (https://www.erlang.org/doc/man/file.html) so I would have assumed it to be exported, but inspection of file.erl shows that it isn't, and never has been. Why earlier versions of dialyzer didn't flag this I don't know, perhaps defaults have changed, but the result is still a regression.

In Erlang/OTP 26 we changed dialyzer to by default warn about missing types and functions. You can pass -Wno_unknown if you do not want these types of warnings. The warning was enabled by default to make sure users catch the type of errors that you have found. You can read more about it in OTP-18439.

The type section of the Erlang documentation can list both exported and un-exported types. At the moment there is no way to distinguish between the two without looking at the source code. The reason why we don't export all types that are documented is because some types are for documentation purposes only and should not be used by the user. That being said I think that file:location/0 falls into the category of types that should be exported.

@jhogberg jhogberg self-assigned this Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

4 participants