Skip to content

Commit 7bae002

Browse files
author
José Valim
committed
Automatically detect when to warn on import
1 parent 65f7d56 commit 7bae002

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

lib/elixir/lib/protocol.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Protocol do
3030
]
3131

3232
# Import the new dsl that holds the new def
33-
import :macros, Protocol.DSL, warn: false
33+
import :macros, Protocol.DSL
3434

3535
# Set up a clear slate to store defined functions
3636
@functions []

lib/elixir/lib/record.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Record do
2929
quote do
3030
defmodule unquote(name) do
3131
@moduledoc false
32-
import Record.DSL, warn: false
32+
import Record.DSL
3333

3434
@record_fields []
3535
@record_types []

lib/elixir/src/elixir_import.erl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ record(Tuple, Receiver, Module) ->
2626
error:badarg -> false
2727
end.
2828

29-
record_warn(_Meta, _Ref, _Opts, nil) -> false;
29+
record_warn(_Meta, _Ref, _Opts, #elixir_scope{module=nil}) -> false;
3030

31-
record_warn(Meta, Ref, Opts, Module) ->
32-
Table = table(Module),
31+
record_warn(Meta, Ref, Opts, S) ->
32+
Table = table(S#elixir_scope.module),
3333
ets:delete(Table, Ref),
34-
case keyfind(warn, Opts) of
35-
{ warn, false } -> false;
36-
false -> ets:insert(Table, { Ref, ?line(Meta) })
37-
end.
34+
35+
Warn =
36+
case keyfind(warn, Opts) of
37+
{ warn, false } -> false;
38+
{ warn, true } -> true;
39+
false -> S#elixir_scope.check_clauses
40+
end,
41+
42+
Warn andalso ets:insert(Table, { Ref, ?line(Meta) }).
3843

3944
recorded_locals(Module) ->
4045
Table = table(Module),
@@ -72,7 +77,7 @@ import(Meta, Ref, Opts, Selector, S) ->
7277
SF#elixir_scope{macros=Macros, macro_macros=TempM}
7378
end,
7479

75-
record_warn(Meta, Ref, Opts, S#elixir_scope.module),
80+
record_warn(Meta, Ref, Opts, S),
7681
SM.
7782

7883
%% IMPORT FUNCTION RELATED HELPERS

lib/elixir/src/elixir_macros.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ translate({defmodule, Meta, [Ref, KV]}, S) ->
213213
{ TRef, S }
214214
end,
215215

216-
MS = FS#elixir_scope{check_clauses=true,local=nil},
216+
MS = FS#elixir_scope{local=nil},
217217
{ elixir_module:translate(Meta, FRef, Block, MS), FS };
218218

219219
translate({Kind, Meta, [Call]}, S) when ?FUNS(Kind) ->

lib/ex_unit/lib/ex_unit/callbacks.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule ExUnit.Callbacks do
4747
@exunit_teardown_all []
4848

4949
@before_compile unquote(__MODULE__)
50-
import unquote(__MODULE__), warn: false
50+
import unquote(__MODULE__)
5151

5252
def __exunit__(:parent) do
5353
unquote(parent)

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ defmodule ExUnit.Case do
3838

3939
use ExUnit.Callbacks, parent: unquote(parent)
4040

41-
import ExUnit.Assertions, warn: false
42-
import ExUnit.Case, warn: false
43-
import ExUnit.DocTest, only: [doctest: 1, doctest: 2], warn: false
41+
import ExUnit.Assertions
42+
import ExUnit.Case
43+
import ExUnit.DocTest, only: [doctest: 1, doctest: 2]
4444
end
4545
end
4646

0 commit comments

Comments
 (0)