From ac35ee08779884728d67d804cc80b0c210c29fd8 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 2 May 2018 10:36:09 +0200 Subject: dialyzer: Do not emit warnings for unreachable funs Warnings are not generated for funs residing in dead code. In particular, warnings like "The created fun has no local return" are no longer generated for funs declared in clauses or functions that cannot be run. --- .../test/small_SUITE_data/results/unused_funs | 5 +++++ .../test/small_SUITE_data/src/unused_funs.erl | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 lib/dialyzer/test/small_SUITE_data/results/unused_funs create mode 100644 lib/dialyzer/test/small_SUITE_data/src/unused_funs.erl (limited to 'lib/dialyzer/test/small_SUITE_data') diff --git a/lib/dialyzer/test/small_SUITE_data/results/unused_funs b/lib/dialyzer/test/small_SUITE_data/results/unused_funs new file mode 100644 index 0000000000..c468457ead --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/results/unused_funs @@ -0,0 +1,5 @@ + +unused_funs.erl:10: The pattern 'error' can never match the type 'other_error' +unused_funs.erl:15: Function not_used/0 will never be called +unused_funs.erl:19: Function foo/1 will never be called +unused_funs.erl:7: Function test/0 has no local return diff --git a/lib/dialyzer/test/small_SUITE_data/src/unused_funs.erl b/lib/dialyzer/test/small_SUITE_data/src/unused_funs.erl new file mode 100644 index 0000000000..c24cf3ea81 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/unused_funs.erl @@ -0,0 +1,21 @@ +%% See also ERL-593. + +-module(unused_funs). + +-export([test/0]). + +test() -> % "has no local return" + Var = outer_scope, + case other_error of + error -> % "can never match" + %% No warnings "no local return" and "_ = 1 can never match 0" (!) + foo(fun() -> {Var, 1 = 0} end) + end. + +not_used() -> % "will never be called" + %% No warnings "no local return" and "1 can never match 0". + foo(fun() -> 1 = 0 end). + +foo(Fun) -> % "will never be called" + 1 = 0, % No pattern match warning (foo/1 is not traversed at all). + Fun(). -- cgit v1.2.3