Skip to content

Instantly share code, notes, and snippets.

@pikeas
Created August 4, 2016 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikeas/6bb79990df3cba069e64b65901c31c0f to your computer and use it in GitHub Desktop.
Save pikeas/6bb79990df3cba069e64b65901c31c0f to your computer and use it in GitHub Desktop.
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
# fails with
# foo.ex:9: The variable _@1 can never match since previous clauses completely covered the type #{'__struct__':='Elixir.Foo', _=>_}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment