Hi,
i have these functions
@spec ai_random_move(board_t()) :: integer()
def ai_random_move(board) do
Enum.random(empty_spots(board))
end
@spec try_win_move(board_t(), String.t()) :: integer() | nil
def try_win_move(board, player) do
Enum.find(empty_spots(board), &winner?(make_move(board, &1, player), player))
end
@spec ai_win_move(board_t(), String.t()) :: integer()
def ai_win_move(board, player) do
try_win_move(board, player) || ai_random_move(board)
end
and i am getting a warning from dialyzer
lib/tictactoe_elixir.ex:154:missing_range
The type specification is missing types returned by function.
Function:
TictactoeElixir.ai_win_move/2
Type specification return types:
integer()
Missing from spec:
nil
This does not seem correct to me, as the nil can never actually be returned due to the ||
. Is this a shortcoming of dialyzer or am i doing something wrong here?
Cheers
Jan-Eric