Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1002

Dialyzer doesn't error when required atom keys were removed from a map

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 22.0, 21.3
    • Fix Version/s: None
    • Component/s: dialyzer
    • Labels:
      None

      Description

      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.

      -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}.
      

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

      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

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            hasse Hans Bolinder
            Reporter:
            rodrigues Victor Rodrigues
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development