Skip to content

Commit 19301b9

Browse files
author
José Valim
committed
Small improvements to records and others
1 parent 02c76da commit 19301b9

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

lib/elixir/lib/record.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,10 @@ defmodule Record do
487487

488488
case remaining do
489489
[] ->
490-
quote do: { unquote_splicing([atom|match]) }
490+
{ :{}, [], [atom|match] }
491491
_ ->
492492
keys = lc { key, _ } inlist remaining, do: key
493-
raise ArgumentError, message: "record #{inspect atom} does not have the keys: #{inspect keys}"
493+
raise ArgumentError, message: "record #{inspect atom} does not have the key: #{inspect hd(keys)}"
494494
end
495495
end
496496

@@ -713,7 +713,7 @@ defmodule Record do
713713
quote do
714714
@doc false
715715
def to_keywords(record) do
716-
unquote(:orddict.from_list(sorted))
716+
unquote(sorted)
717717
end
718718
end
719719
end
@@ -808,11 +808,11 @@ defmodule Record do
808808
end
809809

810810
defp updater_lookup(k, key, values) do
811-
v = find_index(values, key, 1)
811+
index = find_index(values, key, 0)
812812

813813
quote do
814814
case :lists.keyfind(unquote(k), 1, keywords) do
815-
false -> elem(record, unquote(v))
815+
false -> :erlang.element(unquote(index + 2), record)
816816
{_, value} -> value
817817
end
818818
end

lib/elixir/lib/string.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ defmodule String do
149149
def printable?(<<?\a, t :: binary>>), do: printable?(t)
150150

151151
def printable?(<<>>), do: true
152-
def printable?(_), do: false
152+
def printable?(b) when is_binary(b), do: false
153153

154154
@doc """
155155
Divides a string into substrings at each Unicode whitespace

lib/elixir/test/elixir/kernel/errors_test.exs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,13 @@ defmodule Kernel.ErrorsTest do
493493
end
494494

495495
test :invalid_access_protocol_invalid_keywords do
496-
assert_raise ArgumentError, "record Kernel.ErrorsTest.Config does not have the keys: [:foo]", fn ->
496+
assert_raise ArgumentError, "record Kernel.ErrorsTest.Config does not have the key: :foo", fn ->
497497
defmodule ErrorsTest do
498498
def sample(Kernel.ErrorsTest.Config[foo: :bar]), do: true
499499
end
500500
end
501501
end
502502

503-
test :invalid_access_protocol_invalid_keywords_outside_match do
504-
assert_compile_fail ArgumentError,
505-
"record Kernel.ErrorsTest.Config does not have the keys: [:foo]",
506-
'Kernel.ErrorsTest.Config[foo: :bar]'
507-
end
508-
509503
test :invalid_rescue_clause do
510504
assert_compile_fail CompileError,
511505
"nofile:4: invalid rescue clause. The clause should match on an alias, a variable or be in the `var in [alias]` format",

lib/iex/lib/iex/evaluator.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ defmodule IEx.Evaluator do
189189
defp format_function(fun, arity) do
190190
cond do
191191
is_list(arity) ->
192-
"#{fun}/#{Enum.count(arity)}"
192+
"#{fun}/#{length(arity)}"
193193
true ->
194194
"#{fun}/#{arity}"
195195
end

0 commit comments

Comments
 (0)