-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Background
I am trying to implement a couple of protocols in a module but Gradualizer is complaining saying my code is not reachable. The code works without issues, so I am confused.
Code
Here is a simplification of the source code:
defmodule Option do
defmodule Some do
@type t(elem) :: %__MODULE__{val: elem}
defstruct [:val]
defimpl Collectable do
@impl Collectable
def into(option), do: {option, fn acc, _command -> {:done, acc} end}
end
defimpl Enumerable do
@impl Enumerable
def count(_some), do: {:ok, 1}
@impl Enumerable
def member?(some, element), do: {:ok, some.val == element}
@impl Enumerable
def reduce(some, acc, fun)
def reduce(_some, {:halt, acc}, _fun), do: {:halted, acc}
def reduce(some, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(some, &1, fun)}
def reduce([], {:cont, acc}, _fun), do: {:done, acc}
def reduce(%Option.Some{} = some, {:cont, acc}, fun),
do: reduce([], fun.(some.val, acc), fun)
def reduce(val, {:cont, acc}, fun), do: reduce([], fun.(val, acc), fun)
@impl Enumerable
@spec slice(%Option.Some{}) :: {:error, Enumerable.Option.Some}
def slice(_option), do: {:error, __MODULE__}
end
end
endHere the errors:
$ mix gradient
Compiling 1 file (.ex)
Generated simple_monads app
Typechecking files...
lib/option.ex: The clause on line 9 cannot be reached
lib/option.ex: The clause on line 14 cannot be reached
lib/option.ex: The pattern %Option.Some{} on line 28 doesn't have the type any()
line 9: defimpl Collectable do
line 14: defimpl Enumerable do
line 28 does not accept any, but there is a clause for that after. By that logic, the line def reduce([], {:cont, acc}, _fun), do: {:done, acc} does not accept any as the first parameter and yet the tool wont complain.
Simply put, I cover all cases of the spec.
I would expect to see no errors.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working