@@ -572,8 +572,8 @@ defmodule Record do
572572
573573 ## Function generation
574574
575- # Define __record__/1 and __record__/2 as reflection functions
576- # that return the record names and fields.
575+ # Define __record__/1, __record__/2, __record__/3 as reflection
576+ # functions that return the record names and fields.
577577 #
578578 # Note that fields are *not* keywords. They are in the same
579579 # order as given as parameter and reflects the order of the
@@ -592,7 +592,6 @@ defmodule Record do
592592 quoted = lc { k, _ } inlist values do
593593 index = find_index(values, k, 0)
594594 quote do
595- @doc false
596595 def __record__(:index, unquote(k)), do: unquote(index + 1)
597596 end
598597 end
@@ -606,11 +605,11 @@ defmodule Record do
606605 def __record__(:index, arg, _), do: __record__(:index, arg)
607606
608607 @doc false
609- def __record__(kind, _), do: __record__(kind)
608+ def __record__(kind, _), do: __record__(kind)
610609
611610 @doc false
612- def __record__(:name), do: __MODULE__
613- def __record__(:fields), do: unquote(values)
611+ def __record__(:name), do: __MODULE__
612+ def __record__(:fields), do: unquote(values)
614613 end
615614 end
616615
@@ -675,7 +674,11 @@ defmodule Record do
675674 index = find_index(values, k, 0)
676675 quote do
677676 @doc false
678- def __index__(unquote(k)), do: unquote(index + 1)
677+ def __index__(unquote(k)) do
678+ IO.write "[WARNING] #{ __MODULE__ } .__index__/1 is deprecated, " <>
679+ "please use #{ __MODULE__ } .__record__(:index, key) instead\n #{ Exception . format_stacktrace } "
680+ unquote(index + 1)
681+ end
679682 end
680683 end
681684 quote do
@@ -832,7 +835,7 @@ defmodule Record do
832835 @spec update(options, t) :: t
833836 @spec __record__(:name) :: atom
834837 @spec __record__(:fields) :: [{atom, any}]
835- @spec __index__( atom) :: non_neg_integer | nil
838+ @spec __record__(:index, atom) :: non_neg_integer | nil
836839 end
837840 end
838841
0 commit comments