From e068625d7daa46bf01409a3cdfbf22cb68cfd327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 9 Sep 2014 00:09:18 +0200 Subject: [PATCH] Add integer guards around Enum.fetch/2 --- lib/elixir/lib/enum.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/enum.ex b/lib/elixir/lib/enum.ex index 3469e740e6..06c899a6ea 100644 --- a/lib/elixir/lib/enum.ex +++ b/lib/elixir/lib/enum.ex @@ -593,11 +593,11 @@ defmodule Enum do """ @spec fetch(t, integer) :: {:ok, element} | :error - def fetch(collection, n) when is_list(collection) and n >= 0 do + def fetch(collection, n) when is_list(collection) and is_integer(n) and n >= 0 do do_fetch(collection, n) end - def fetch(collection, n) when n >= 0 do + def fetch(collection, n) when is_integer(n) and n >= 0 do res = Enumerable.reduce(collection, {:cont, 0}, fn(entry, acc) -> if acc == n do @@ -613,7 +613,7 @@ defmodule Enum do end end - def fetch(collection, n) when n < 0 do + def fetch(collection, n) when is_integer(n) and n < 0 do do_fetch(reverse(collection), abs(n + 1)) end