Skip to content

Mixed atom/domain map update incorrectly makes the atom field mandatory #15858

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

The following code demonstrates that map update incorrectly infers input domain with mixed keys

Repro:

    defmodule MixedKey do
      def replace(m, flag) do
        key = if flag, do: :a, else: 1
        %{m | key => :new}
      end

      def run, do: replace(%{1 => :old}, false)
    end

    IO.inspect(MixedKey.run()) # %{1 => :new}

Result: the code works fine but reports a false positive warning:

warning: incompatible types given to replace/2:

    replace(%{1 => :old}, false)

given types:

    %{integer() => :old}, false

but expected one of:

    %{..., a: term()}, term()

└─ iex:25: MixedKey.run/0

Note this issue is distinct from #15625

Expected behavior

No false positive warning. atom keys should not be inferred as required unless the whole kay type is constrained to atoms

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