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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 22.0, 21.3
    • Fix Version/s: 23.0
    • 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}.
      
      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      $ 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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: