@@ -745,12 +745,11 @@ defmodule Module do
745
745
746
746
Module.get_attribute(__MODULE__, :foo, true)
747
747
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.
754
753
755
754
## Examples
756
755
@@ -764,8 +763,9 @@ defmodule Module do
764
763
end
765
764
766
765
"""
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
769
769
assert_not_compiled!(:get_attribute, module)
770
770
table = data_table_for(module)
771
771
@@ -777,9 +777,8 @@ defmodule Module do
777
777
cond do
778
778
:lists.member(key, acc) ->
779
779
[]
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 } , " <>
783
782
"please remove access to @#{ key } or explicitly set it to nil before access\n "
784
783
nil
785
784
true ->
0 commit comments