Hi Everybody,
Thank you for this amazing community and of course for Elixir.
When learning Elixir I discovered strange warning from dialyzer that doesn’t make sense for the following function:
defmodule TestThis.SomeStruct do
defstruct present?: nil,
first: nil,
second: nil,
third: nil,
fifth: nil,
sixth: nil
@type t :: %__MODULE__{
present?: boolean,
first: String.t(),
second: atom,
third: String.t(),
fifth: String.t(),
sixth: String.t()
}
# THIS will show warning that doesn't make sense:
@spec for_test(false) :: t()
def for_test(false) do
%__MODULE__{
present?: false,
first: "",
second: :just_for_test
}
end
# THIS is OK for some reason:
@spec for_test(true, String.t(), atom, String.t(), String.t(), String.t()) :: t()
def for_test(true, first, second, third, fifth, sixth) do
%__MODULE__{
present?: true,
first: first,
second: second,
third: third,
fifth: fifth,
sixth: sixth
}
end
end
I’m thinking about opening a bug report but first I wanted to check with you since I might be doing something wrong.
You can get full project generated by mix
from GitHub: https://github.com/rudolfvesely/elixir-lang-static_analysis_warning
Thank you.
Kind regards,
Rudolf Vesely