Here's a minimum broken example in Elixir 1.3:
defmodule Foo do
@type t :: %__MODULE__{x: non_neg_integer}
defstruct x: 0
@spec test(t) :: t
def test(%__MODULE__{} = foo), do: test2(foo)
@spec test2(t) :: t
defp test2(%__MODULE__{} = foo), do: %__MODULE__{foo | x: 5}
end
This fails to type check with: foo.ex:9: The variable _@1 can never match since previous clauses completely covered the type #{'__struct__':='Elixir.Foo', _=>_}
.
I've searched and searched and cannot for the life of me find an explanation of what this means, or how to fix it.