Skip to content

map_(get|put|update) ignore atom fields with static term() key #15932

Description

@lukaszsamson

Existing issue

  • I have searched existing issues and could not find a duplicate.

Elixir and Erlang/OTP versions

Erlang/OTP 28 [erts-16.4.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Interactive Elixir (1.21.0-dev)

Operating system

any

Current behavior

Map.fetch(%{a: 1}, k) with k :: term() can return {:ok, 1} yet this repro shows the implementation neglects this

    import Module.Types.Descr
    m = closed_map(a: {integer(), false})

    IO.inspect(map_get(m, term()), label: "map_get term")
    IO.inspect(map_get(m, atom()), label: "map_get atom")

    {:ok, r} = map_put(m, term(), pid())
    IO.puts(to_quoted_string(r))
    IO.inspect(subtype?(closed_map(a: {pid(), false}), r), label: "subtype (must be true)")

    {_, d, _} = map_update(m, term(), atom([:x]), false)
    IO.puts(to_quoted_string(d))

Prints:

map_get term: :error
map_get atom: {:ok, %{bitmap: 8}}

%{
  atom() => pid(),
  bitstring() => pid(),
  float() => pid(),
  fun() => pid(),
  integer() => pid(),
  list() => pid(),
  map() => pid(),
  pid() => pid(),
  port() => pid(),
  reference() => pid(),
  tuple() => pid(),
  a: integer()
}
subtype (must be true): false

%{a: integer()}

This issue affects only API. Real code produces dynamic(term()) keys

Expected behavior

Correct handling of term() keys

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions