【发布时间】:2016-12-12 12:45:49
【问题描述】:
这是 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', _=>_}。
我一直在搜索,但终生无法找到解释这意味着什么,或者如何解决它。
【问题讨论】: