File 0649-dialyzer-Improve-the-warning-tagged-fun_app_args.patch of Package erlang

From 6d9d4af8725f26972481b2e997c54ee5b3eafb29 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Wed, 24 Apr 2019 09:52:54 +0200
Subject: [PATCH] dialyzer: Improve the warning tagged 'fun_app_args'

The mismatching argument positions are included.
---
 lib/dialyzer/src/dialyzer.erl                           |  7 +++++--
 lib/dialyzer/src/dialyzer_dataflow.erl                  |  7 ++++++-
 lib/dialyzer/test/small_SUITE_data/results/fun_app_args |  3 +++
 lib/dialyzer/test/small_SUITE_data/src/fun_app_args.erl | 12 ++++++++++++
 4 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 lib/dialyzer/test/small_SUITE_data/results/fun_app_args
 create mode 100644 lib/dialyzer/test/small_SUITE_data/src/fun_app_args.erl

diff --git a/lib/dialyzer/src/dialyzer.erl b/lib/dialyzer/src/dialyzer.erl
index 185c8c9ae6..a168b3c8c5 100644
--- a/lib/dialyzer/src/dialyzer.erl
+++ b/lib/dialyzer/src/dialyzer.erl
@@ -326,9 +326,12 @@ message_to_string({call_to_missing, [M, F, A]}) ->
 message_to_string({exact_eq, [Type1, Op, Type2]}) ->
   io_lib:format("The test ~s ~s ~s can never evaluate to 'true'\n",
 		[Type1, Op, Type2]);
-message_to_string({fun_app_args, [Args, Type]}) ->
+message_to_string({fun_app_args, [ArgNs, Args, Type]}) ->
+  PositionString = form_position_string(ArgNs),
   io_lib:format("Fun application with arguments ~s will fail"
-		" since the function has type ~s\n", [Args, Type]);
+		" since the function has type ~s,"
+                " which differs in the ~s argument\n",
+                [Args, Type, PositionString]);
 message_to_string({fun_app_no_fun, [Op, Type, Arity]}) ->
   io_lib:format("Fun application will fail since ~s :: ~s"
 		" is not a function of arity ~w\n", [Op, Type, Arity]);
diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl
index 45b4abb253..f7aa167f5c 100644
--- a/lib/dialyzer/src/dialyzer_dataflow.erl
+++ b/lib/dialyzer/src/dialyzer_dataflow.erl
@@ -405,8 +405,13 @@ handle_apply(Tree, Map, State) ->
                                     t_fun_args(OpType1, 'universe')),
 	      case any_none(NewArgs) of
 		true ->
+                  EnumNewArgs = lists:zip(lists:seq(1, length(NewArgs)),
+                                          NewArgs),
+                  ArgNs = [Arg ||
+                            {Arg, Type} <- EnumNewArgs, t_is_none(Type)],
 		  Msg = {fun_app_args,
-			 [format_args(Args, ArgTypes, State),
+			 [ArgNs,
+			  format_args(Args, ArgTypes, State),
 			  format_type(OpType, State)]},
 		  State3 = state__add_warning(State2, ?WARN_FAILING_CALL,
 					      Tree, Msg),
diff --git a/lib/dialyzer/test/small_SUITE_data/results/fun_app_args b/lib/dialyzer/test/small_SUITE_data/results/fun_app_args
new file mode 100644
index 0000000000..ac153a6fb2
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/results/fun_app_args
@@ -0,0 +1,3 @@
+
+fun_app_args.erl:12: Fun application with arguments ('b',[]) will fail since the function has type 'c' | fun(('a',[]) -> any()), which differs in the 1st argument
+fun_app_args.erl:12: The created fun has no local return
diff --git a/lib/dialyzer/test/small_SUITE_data/src/fun_app_args.erl b/lib/dialyzer/test/small_SUITE_data/src/fun_app_args.erl
new file mode 100644
index 0000000000..b4409bc550
--- /dev/null
+++ b/lib/dialyzer/test/small_SUITE_data/src/fun_app_args.erl
@@ -0,0 +1,12 @@
+-module(fun_app_args).
+
+-export([t/1]).
+
+-type ft() :: fun((a, []) -> any()).
+
+-record(r, {
+    h = c :: c | ft()
+}).
+
+t(#r{h = H}) ->
+    fun(_) -> (H)(b, []) end.
-- 
2.16.4

openSUSE Build Service is sponsored by