File 0561-dialyzer-Fix-maps-as-parameter-of-opaque-types.patch of Package erlang

From b67ddedf0212079204effbb061f31b7366dff95b Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Wed, 20 Feb 2019 15:51:09 +0100
Subject: [PATCH 2/2] dialyzer: Fix maps as parameter of opaque types

The clause added for maps in commit 1a7c41be is corrected.
---
 lib/dialyzer/test/opaque_SUITE_data/results/para          |  1 +
 lib/dialyzer/test/opaque_SUITE_data/src/para/para4.erl    | 11 +++++++++++
 .../test/opaque_SUITE_data/src/para/para4_adt.erl         | 12 ++++++++++++
 lib/hipe/cerl/erl_types.erl                               | 15 ++++++++++++---
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/lib/dialyzer/test/opaque_SUITE_data/results/para b/lib/dialyzer/test/opaque_SUITE_data/results/para
index 37b5b7b44e..eca445315c 100644
--- a/lib/dialyzer/test/opaque_SUITE_data/results/para
+++ b/lib/dialyzer/test/opaque_SUITE_data/results/para
@@ -29,5 +29,6 @@ para4.erl:74: Attempt to test for equality between a term of type para4_adt:int(
 para4.erl:79: Attempt to test for equality between a term of type para4_adt:int(2 | 3 | 4) and a term of opaque type para4_adt:int(5 | 6 | 7)
 para4.erl:84: Attempt to test for equality between a term of type para4_adt:un(3 | 4) and a term of opaque type para4_adt:un(1 | 2)
 para4.erl:89: Attempt to test for equality between a term of type para4_adt:tup({_,_}) and a term of opaque type para4_adt:tup(tuple())
+para4.erl:94: Attempt to test for equality between a term of type para4_adt:t(#{1=>'a'}) and a term of opaque type para4_adt:t(#{2=>'b'})
 para5.erl:13: Attempt to test for inequality between a term of type para5_adt:dd(atom()) and a term of opaque type para5_adt:d()
 para5.erl:8: The test para5_adt:d() =:= para5_adt:d() can never evaluate to 'true'
diff --git a/lib/dialyzer/test/opaque_SUITE_data/src/para/para4.erl b/lib/dialyzer/test/opaque_SUITE_data/src/para/para4.erl
index b9794672a9..8cd049169d 100644
--- a/lib/dialyzer/test/opaque_SUITE_data/src/para/para4.erl
+++ b/lib/dialyzer/test/opaque_SUITE_data/src/para/para4.erl
@@ -88,6 +88,11 @@ adt_tt13() ->
     I2 = adt_tup2(),
     I1 =:= I2. % opaque attempt
 
+adt_tt14() ->
+    I1 = adt_map(),
+    I2 = adt_map2(),
+    I1 =:= I2.
+
 y3() ->
     {a, 3}.
 
@@ -132,3 +137,9 @@ adt_tup() ->
 
 adt_tup2() ->
     para4_adt:tup2().
+
+adt_map() ->
+    para4_adt:map().
+
+adt_map2() ->
+    para4_adt:map2().
diff --git a/lib/dialyzer/test/opaque_SUITE_data/src/para/para4_adt.erl b/lib/dialyzer/test/opaque_SUITE_data/src/para/para4_adt.erl
index 407dd198a7..06a6c22677 100644
--- a/lib/dialyzer/test/opaque_SUITE_data/src/para/para4_adt.erl
+++ b/lib/dialyzer/test/opaque_SUITE_data/src/para/para4_adt.erl
@@ -8,6 +8,8 @@
 
 -export([tup/0, tup2/0]).
 
+-export([map/0, map2/0]).
+
 -export_type([t/1, y/1, int/1, tup/1, un/1]).
 
 -type ai() :: atom() | integer().
@@ -106,3 +108,13 @@ tup() ->
 
 tup2() ->
     foo:tup2().
+
+-spec map() -> t(#{2 => b}).
+
+map() ->
+    foo:map().
+
+-spec map2() -> t(#{1 => a}).
+
+map2() ->
+    foo:map2().
diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl
index c3b9fd48a1..d61cd8664c 100644
--- a/lib/hipe/cerl/erl_types.erl
+++ b/lib/hipe/cerl/erl_types.erl
@@ -3148,9 +3148,18 @@ is_compat_arg(?list(Contents1, Termination1, Size1),
 is_compat_arg(?product(Types1), ?product(Types2)) ->
   is_compat_list(Types1, Types2);
 is_compat_arg(?map(Pairs1, DefK1, DefV1), ?map(Pairs2, DefK2, DefV2)) ->
-  (is_compat_list(Pairs1, Pairs2) andalso
-   is_compat_arg(DefK1, DefK2) andalso
-   is_compat_arg(DefV1, DefV2));
+  {Ks1, _, Vs1} = lists:unzip3(Pairs1),
+  {Ks2, _, Vs2} = lists:unzip3(Pairs2),
+  Key1 = t_sup([DefK1 | Ks1]),
+  Key2 = t_sup([DefK2 | Ks2]),
+  case is_compat_arg(Key1, Key2) of
+    true ->
+      Value1 = t_sup([DefV1 | Vs1]),
+      Value2 = t_sup([DefV2 | Vs2]),
+      is_compat_arg(Value1, Value2);
+    false ->
+      false
+  end;
 is_compat_arg(?tuple(?any, ?any, ?any), ?tuple(_, _, _)) -> false;
 is_compat_arg(?tuple(_, _, _), ?tuple(?any, ?any, ?any)) -> false;
 is_compat_arg(?tuple(Elements1, Arity, _),
-- 
2.16.4

openSUSE Build Service is sponsored by