这是 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
这无法键入检查:foo.ex:9: The variable _@1 can never match since previous clauses completely covered the type #{'__struct__':='Elixir.Foo', _=>_}
。
我一直在搜索和搜索,但终其一生都找不到解释这意味着什么,或者如何解决它。