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

ERL-1002: Dialyzer doesn't error when required atom keys were removed from a map #3829

Closed
OTP-Maintainer opened this issue Jul 11, 2019 · 3 comments
Assignees
Labels
bug Issue is reported as a bug priority:medium team:VM Assigned to OTP team VM
Milestone

Comments

@OTP-Maintainer
Copy link

Original reporter: rodrigues
Affected versions: OTP-22.0, OTP-21.3
Fixed in version: OTP-23.0
Component: dialyzer
Migrated from: https://bugs.erlang.org/browse/ERL-1002


I believe the following behaviour is a bug, as I specify that a function should return a map with a certain atom key (required), but it could never return it, and dialyzer still passes.

{code:erlang}
-module(test).
-export([foo/0]).

-type t() :: #{a := non_neg_integer()}.

-spec foo() -> t().
%% this passes in dialyzer, but I think it's a bug,
%% as it will always return a map without the key a
foo() -> maps:remove(a, #{a => 2}).

%% this passes in dialyzer, as expected
%% foo() -> #{a => 2}.

%% only for these the required key is checked
%% foo() -> #{}.
%% foo() -> #{another => thing}.
{code}

{code:shell}
$ dialyzer test.erl
  Checking whether the PLT /Users/rodrigues/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis... done in 0m0.12s
done (passed successfully)
{code}

FYI, if it helps, the context where this was discovered: https://elixirforum.com/t/elixir-allows-map-functions-to-manipulate-structs/23826/14?u=rodrigues
@OTP-Maintainer
Copy link
Author

hasse said:

Does https://github.com/erlang/otp/pull/2392 work for you?

@OTP-Maintainer
Copy link
Author

rodrigues said:

Hi Hans, yes, it works fine for me, thanks! 👍

In that example, now I get:

{{test.erl:6: Invalid type specification for function test:foo/0. The success typing is}}
{{() -> #{}}}

@OTP-Maintainer
Copy link
Author

hasse said:

Thanks for testing. I've merged commit
a62aed81c56c724f7dd7040adecaa28a78e5d37f to erlang:master.

@OTP-Maintainer OTP-Maintainer added bug Issue is reported as a bug team:VM Assigned to OTP team VM priority:medium labels Feb 10, 2021
@OTP-Maintainer OTP-Maintainer added this to the OTP-23.0 milestone Feb 10, 2021
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 priority:medium team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

2 participants