elixir icon indicating copy to clipboard operation
elixir copied to clipboard

String.split_at/2 gives wrong output for some floating point as second argument

Open SocialfiPanda opened this issue 12 years ago • 0 comments

iex(1)> String.split_at("abc", -0.1)
{"abc", ""}
iex(2)> String.split_at("abc", -7.1)
{"", "abc"}
iex(3)>  String.split_at("abc", 0.1)
** (FunctionClauseError) no function clause matching in String.do_split_at/4 
    (elixir) lib/string.ex:377: String.do_split_at({"b", "c"}, 1, 0.1, "a")
iex(4)>  String.split_at("abc", 7.1)
{"abc", ""}

I think we should only match integer indices, just as the spec implied @spec split_at(t, integer) :: {t, t}. So all of the above examples should throw FunctionClauseError.

SocialfiPanda avatar Nov 02 '14 02:11 SocialfiPanda