@@ -2,9 +2,7 @@ defmodule Module.Types do
22 @ moduledoc false
33
44 alias Module.Types . { Descr , Expr , Pattern , Helpers }
5-
65 # TODO: Consider passing inferred types from infer into warnings
7- # TODO: Consider removing code from locals tracker
86
97 # These functions are not inferred because they are added/managed by the compiler
108 @ no_infer [ __protocol__: 1 , behaviour_info: 1 ]
@@ -32,18 +30,18 @@ defmodule Module.Types do
3230
3331 unreachable =
3432 for { fun_arity , _kind , _meta , _defaults } = info <- private ,
35- maybe_warn_unused ( info , local_sigs , used , env ) ,
33+ warn_unused_def ( info , local_sigs , used , env ) ,
3634 not is_map_key ( local_sigs , fun_arity ) ,
3735 do: fun_arity
3836
3937 { Map . new ( types ) , unreachable }
4038 end
4139
42- defp maybe_warn_unused ( { _fun_arity , _kind , false , _ } , _reachable , _used , _env ) do
40+ defp warn_unused_def ( { _fun_arity , _kind , false , _ } , _reachable , _used , _env ) do
4341 :ok
4442 end
4543
46- defp maybe_warn_unused ( { fun_arity , kind , meta , 0 } , reachable , used , env ) do
44+ defp warn_unused_def ( { fun_arity , kind , meta , 0 } , reachable , used , env ) do
4745 case meta == false or Map . has_key? ( reachable , fun_arity ) or fun_arity in used do
4846 true -> :ok
4947 false -> :elixir_errors . file_warn ( meta , env , __MODULE__ , { :unused_def , fun_arity , kind } )
@@ -52,7 +50,7 @@ defmodule Module.Types do
5250 :ok
5351 end
5452
55- defp maybe_warn_unused ( { tuple , kind , meta , default } , reachable , used , env ) when default > 0 do
53+ defp warn_unused_def ( { tuple , kind , meta , default } , reachable , used , env ) when default > 0 do
5654 { name , arity } = tuple
5755 min = arity - default
5856 max = arity
@@ -93,25 +91,27 @@ defmodule Module.Types do
9391 context
9492 end )
9593
96- context =
97- for { fun_arity , pending } <- context . local_used , pending != [ ] , reduce: context do
98- context ->
99- { _fun_arity , kind , _meta , clauses } = List . keyfind ( defs , fun_arity , 0 )
100- { _kind , _inferred , mapping } = Map . fetch! ( context . local_sigs , fun_arity )
101-
102- clauses_indexes =
103- for type_index <- pending , { clause_index , ^ type_index } <- mapping , do: clause_index
104-
105- Enum . reduce ( clauses_indexes , context , fn clause_index , context ->
106- { meta , _args , _guards , _body } = Enum . fetch! ( clauses , clause_index )
107- stack = % { stack | function: fun_arity }
108- Helpers . warn ( __MODULE__ , { :unused_clause , kind , fun_arity } , meta , stack , context )
109- end )
110- end
111-
94+ context = warn_unused_clauses ( defs , stack , context )
11295 context . warnings
11396 end
11497
98+ defp warn_unused_clauses ( defs , stack , context ) do
99+ for { fun_arity , pending } <- context . local_used , pending != [ ] , reduce: context do
100+ context ->
101+ { _fun_arity , kind , _meta , clauses } = List . keyfind ( defs , fun_arity , 0 )
102+ { _kind , _inferred , mapping } = Map . fetch! ( context . local_sigs , fun_arity )
103+
104+ clauses_indexes =
105+ for type_index <- pending , { clause_index , ^ type_index } <- mapping , do: clause_index
106+
107+ Enum . reduce ( clauses_indexes , context , fn clause_index , context ->
108+ { meta , _args , _guards , _body } = Enum . fetch! ( clauses , clause_index )
109+ stack = % { stack | function: fun_arity }
110+ Helpers . warn ( __MODULE__ , { :unused_clause , kind , fun_arity } , meta , stack , context )
111+ end )
112+ end
113+ end
114+
115115 defp local_handler ( fun_arity , stack , context , finder ) do
116116 case context . local_sigs do
117117 % { ^ fun_arity => { kind , inferred , _mapping } } ->
0 commit comments