From 477fd95a1f404175c133f30a9e10e7a27ce400b8 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Mon, 19 Dec 2011 16:04:27 +0100
Subject: Handle nowarn_unused_function like the compiler does

---
 lib/dialyzer/src/dialyzer_analysis_callgraph.erl       | 13 +++++++++++--
 .../user_SUITE_data/results/nowarn_unused_function_1   |  2 ++
 .../user_SUITE_data/results/nowarn_unused_function_2   |  0
 .../user_SUITE_data/results/nowarn_unused_function_3   |  3 +++
 .../user_SUITE_data/src/nowarn_unused_function_1.erl   | 18 ++++++++++++++++++
 .../user_SUITE_data/src/nowarn_unused_function_2.erl   | 18 ++++++++++++++++++
 .../user_SUITE_data/src/nowarn_unused_function_3.erl   | 16 ++++++++++++++++
 7 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_1
 create mode 100644 lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_2
 create mode 100644 lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_3
 create mode 100644 lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_1.erl
 create mode 100644 lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_2.erl
 create mode 100644 lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_3.erl

(limited to 'lib')

diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
index b42f5e8191..458f3a4c81 100644
--- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
+++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
@@ -359,8 +359,17 @@ store_core(Mod, Core, NoWarn, Callgraph, CServer) ->
   store_code_and_build_callgraph(Mod, LabeledCore, Callgraph, CServer3, NoWarn).
 
 abs_get_nowarn(Abs, M) ->
-  [{M, F, A}
-   || {attribute, _, compile, {nowarn_unused_function, {F, A}}} <- Abs].
+  Opts = lists:flatten([C || {attribute, _, compile, C} <- Abs]),
+  Warn = erl_lint:bool_option(warn_unused_function, nowarn_unused_function,
+                              true, Opts),
+  case Warn of
+    false ->
+      [{M, F, A} || {function, _, F, A, _} <- Abs]; % all functions
+    true ->
+      [{M, F, A} ||
+        {nowarn_unused_function, FAs} <- Opts,
+        {F, A} <- lists:flatten([FAs])]
+  end.
 
 get_exported_types_from_core(Core) ->
   Attrs = cerl:module_attrs(Core),
diff --git a/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_1 b/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_1
new file mode 100644
index 0000000000..de416455e2
--- /dev/null
+++ b/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_1
@@ -0,0 +1,2 @@
+
+nowarn_unused_function_1.erl:17: Function f3/1 will never be called
diff --git a/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_2 b/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_2
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_3 b/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_3
new file mode 100644
index 0000000000..8ae78673d5
--- /dev/null
+++ b/lib/dialyzer/test/user_SUITE_data/results/nowarn_unused_function_3
@@ -0,0 +1,3 @@
+
+nowarn_unused_function_3.erl:12: Function f2/1 will never be called
+nowarn_unused_function_3.erl:9: Function f1/1 will never be called
diff --git a/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_1.erl b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_1.erl
new file mode 100644
index 0000000000..fcce532f73
--- /dev/null
+++ b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_1.erl
@@ -0,0 +1,18 @@
+%% Test that option 'nowarn_unused_funcion' works similarly in
+%% Dialyzer as in the compiler.
+
+-module(nowarn_unused_function_1).
+
+-compile(warn_unused_function).
+
+-compile({nowarn_unused_function,f1/1}).
+f1(_) ->
+    a.
+
+-compile({nowarn_unused_function,[{f2,1}]}).
+f2(_) ->
+    a.
+
+-compile({warn_unused_function,[{f3,1}]}).
+f3(_) ->
+    a.
diff --git a/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_2.erl b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_2.erl
new file mode 100644
index 0000000000..9bc3ab14ea
--- /dev/null
+++ b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_2.erl
@@ -0,0 +1,18 @@
+%% Test that option 'nowarn_unused_funcion' works similarly in
+%% Dialyzer as in the compiler.
+
+-module(nowarn_unused_function_2).
+
+-compile(nowarn_unused_function).
+
+-compile({warn_unused_function,f1/1}).
+f1(_) ->
+    a.
+
+-compile({warn_unused_function,[{f2,1}]}).
+f2(_) ->
+    a.
+
+-compile({nowarn_unused_function,[{f3,1}]}).
+f3(_) ->
+    a.
diff --git a/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_3.erl b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_3.erl
new file mode 100644
index 0000000000..604c5e436b
--- /dev/null
+++ b/lib/dialyzer/test/user_SUITE_data/src/nowarn_unused_function_3.erl
@@ -0,0 +1,16 @@
+%% Test that option 'nowarn_unused_funcion' works similarly in
+%% Dialyzer as in the compiler.
+
+-module(nowarn_unused_function_3).
+
+-compile({warn_unused_function,[{f1,1},{f2,1}]}).
+-compile({nowarn_unused_function,[{f3,1}]}).
+
+f1(_) ->
+    a.
+
+f2(_) ->
+    a.
+
+f3(_) ->
+    a.
-- 
cgit v1.2.3