@@ -745,12 +745,11 @@ defmodule Module do
745745
746746 Module.get_attribute(__MODULE__, :foo, true)
747747
748- Notice the third argument is used to indicate if a warning
749- should be emitted when the attribute was not previously defined.
750- `warn` may also be a stacktrace, which will be used in the
751- warning. The default value for `warn` is false for direct calls
752- but the `@foo` macro sets it to the proper stacktrace automatically,
753- warning every time `@foo` is used but not set previously.
748+ Notice the third argument may be given to indicate a stacktrace
749+ to be emitted when the attribute was not previously defined.
750+ The default value for `warn` is nil for direct calls but the `@foo`
751+ macro sets it to the proper stacktrace automatically, warning
752+ every time `@foo` is used but not set previously.
754753
755754 ## Examples
756755
@@ -764,8 +763,9 @@ defmodule Module do
764763 end
765764
766765 """
767- @spec get_attribute(module, atom, warn :: boolean | [tuple]) :: term
768- def get_attribute(module, key, warn // false) when is_atom(key) do
766+ @spec get_attribute(module, atom, warn :: nil | [tuple]) :: term
767+ def get_attribute(module, key, warn // nil) when
768+ is_atom(key) and (is_list(warn) or nil?(warn)) do
769769 assert_not_compiled!(:get_attribute, module)
770770 table = data_table_for(module)
771771
@@ -777,9 +777,8 @@ defmodule Module do
777777 cond do
778778 :lists.member(key, acc) ->
779779 []
780- warn ->
781- stack = is_list(warn) and warn
782- :elixir_errors.warn "#{ Exception . format_caller ( stack ) } undefined module attribute @#{ key } , " <>
780+ is_list(warn) ->
781+ :elixir_errors.warn "#{ Exception . format_caller ( warn ) } undefined module attribute @#{ key } , " <>
783782 "please remove access to @#{ key } or explicitly set it to nil before access\n "
784783 nil
785784 true ->
0 commit comments