<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1027" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">I’ve not used –opaque type specifiers much, but so far I’ve gotten the impression that it should be the same as –type within the module the type is declared in.
<o:p></o:p></p>
<p class="MsoNormal">Now I’m facing differences … why? <span style="font-family:Wingdings">
J</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ve managed to reduce my real source code down to a small snippet. I have a custom type mytest() that I’d like to make opaque for other modules. But here is the first version:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-module(dummy).<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-export([test/1]).<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-<span style="background:yellow;mso-highlight:yellow">type</span> mytype() :: proplists:proplist() | atom().<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-spec test(A :: mytype()) -> term().<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">test(A) -><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> case something(A) of<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> true -><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> throw(up);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> _ -><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> proplists:get_value(test, A)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> end.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-spec something(A :: mytype()) -> boolean().<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">something(A) -><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"> is_atom(A).<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Dialyzer reports no issue on the above snippet. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">If I change the type to opaque in line 3:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-opaque mytype() :: proplists:proplist() | atom().<o:p></o:p></span></p>
<p class="MsoNormal">then Dialyzer reports:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">dummy.erl:6: Function test/1 has no local return<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">dummy.erl:11: The call proplists:get_value('test',A::dummy:mytype()) contains an opaque term as 2nd argument when terms of different types are expected in these positions<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Then adding module name to the type reference in the 2 function specs:<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-spec test(A ::
<span style="background:yellow;mso-highlight:yellow">dummy:</span>mytype()) -> term().<o:p></o:p></span></p>
<p class="MsoNormal">and<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas">-spec something(A ::
<span style="background:yellow;mso-highlight:yellow">dummy:</span>mytype()) -> boolean().<o:p></o:p></span></p>
<p class="MsoNormal">makes Dialyzer happy again. Why? <o:p></o:p></p>
<p class="MsoNormal">And do I have a type error or not <span style="font-family:Wingdings">
J</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">/Ola<o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:Consolas"><o:p> </o:p></span></p>
</div>
</body>
</html>