File 1120-dialyzer-Clarify-how-to-declare-records-used-in-matc.patch of Package erlang

From 6be75e50394317607af7a5501ef4e6acfef86a35 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Tue, 9 Feb 2021 14:55:26 +0100
Subject: [PATCH] dialyzer: Clarify how to declare records used in match
 patterns

See also https://bugs.erlang.org/browse/ERL-892.
---
 system/doc/reference_manual/typespec.xml | 27 ++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/system/doc/reference_manual/typespec.xml b/system/doc/reference_manual/typespec.xml
index b46cf0e8e8..c800301edc 100644
--- a/system/doc/reference_manual/typespec.xml
+++ b/system/doc/reference_manual/typespec.xml
@@ -467,6 +467,33 @@
       Any unspecified fields are assumed to have the type in the original
       record declaration.
     </p>
+    <note>
+      <p>When records are used to create patterns for ETS and
+        Mnesia match functions, Dialyzer may need some help not to emit
+        bad warnings. For example:</p>
+
+<pre>
+    -type height() :: pos_integer().
+    -record(person, {name :: string(), height :: height()}).
+
+    lookup(Name, Tab) ->
+	ets:match_object(Tab, #person{name = Name, _ = '_'}).</pre>
+
+      <p>Dialyzer will emit a warning since <c>'_'</c> is not in the
+        type of record field <c>height</c>.</p>
+
+      <p>The recommended way of dealing with this is to declare the
+        smallest record field types to accommodate all your needs,
+        and then create refinements as needed. The modified example:</p>
+
+<pre>
+    -record(person, {name :: string(), height :: height() | '_'}).
+
+    -type person() :: #person{height :: height()}.</pre>
+
+      <p>In specifications and type declarations the type
+        <c>person()</c> is to be preferred before <c>#person{}</c>.</p>
+    </note>
   </section>
 
   <section>
-- 
2.26.2

openSUSE Build Service is sponsored by