Skip to content

Structs nested in domain-key maps are not inferred #14915

@sabiwara

Description

@sabiwara

Elixir and Erlang/OTP versions

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

Elixir 1.19.3 (compiled with Erlang/OTP 28)

Also main.

Current behavior

defmodule Repro do
  def update(%{"foo" => %Date{year: year} = date}) do
    %Date{date | year: year + 1}
  end
end
    warning: a struct for Date is expected on struct update:

        %Date{date | year: year + 1}

    but got type:

        dynamic()

    where "date" was given the type:

        # type: dynamic()
        # from: lib/repro.ex:2:14
        %{"foo" => %Date{year: year} = date}

Expected behavior

No warning, like if we use atom keys in the map (def update(%{foo: %Date{year: year} = date}) do).

Even for domain keys, I think variables matching a nested pattern should be inferred with this pattern?
Not sure if it is just a temporary state that will be addressed by #14558 or if it is just a bug.

Originally reported here.

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