<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-06-30 15:50 GMT+02:00 Paul Guyot <span dir="ltr"><<a href="mailto:pguyot@kallisys.net" target="_blank">pguyot@kallisys.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Alex, Tobias,<div><br></div><div>Indeed, the function constructs the set using gb_sets API and then the result is embedded in the module with erl_parse:abstract/1.</div><div>The current solution consists in adding a call to an identity/1 function in the generated replacement code. This function is exported from the parse transform module of type fun(any()) -> any(). Since the parse transform is in another application, dialyzer seems to take its specification for granted (?). It's a cheaper equivalent of binary_to_term(term_to_binary(<wbr>V)), although not free (it's still a remote call).</div></div></blockquote><div><br></div><div>Sorry, I misunderstood.</div><div><br></div><div>If you are worried about the remote call, you can probably achieve the same thing by having a local call and exporting the function. You need the export to confuse Dialyzer enough to label it as any().</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="HOEnZb"><font color="#888888"><div><br></div><div>Paul</div></font></span><div><div class="h5"><div><br></div><div><div><blockquote type="cite"><div>On 30 Jun 2017, at 15:29, Alex S. <<a href="mailto:alex0player@gmail.com" target="_blank">alex0player@gmail.com</a>> wrote:</div><br class="m_8510748567866083224Apple-interchange-newline"><div><div style="word-wrap:break-word">he is constructing it, after parse transform takes place.<br><div><blockquote type="cite"><div>30 июня 2017 г., в 14:27, Tobias Lindahl <<a href="mailto:tobias.lindahl@gmail.com" target="_blank">tobias.lindahl@gmail.com</a>> написал(а):</div><br class="m_8510748567866083224Apple-interchange-newline"><div><div dir="ltr">It seems to me that the gb_sets:from_list/1 should give the correct type for your function even if the spec is not taken into account.<div><br></div><div>In that case, the value you are getting warnings for comes from somewhere else. Could it be that you are deconstructing the opaque type somewhere?</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-25 18:56 GMT+02:00 Paul Guyot <span dir="ltr"><<a href="mailto:pguyot@kallisys.net" target="_blank">pguyot@kallisys.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I do have a parse transform that replaces the body of a 0-arity function with its result, as evaluated at compile time.<br>
I am looking for a way to avoid an opaque violation warning from dialyzer when this function returns, say, a gb_sets:set(). The spec is properly copied into the parsed tree, but dialyzer just ignores it.<br>
<br>
Typically, such a function would load data from a file and create a gb_sets:set() from this data.<br>
<br>
-spec f() -> gb_sets:set(unicode:unicode_bi<wbr>nary()).<br>
f() -><br>
{ok, Content} = file:read_file(?FILENAME),<br>
List0 = binary:split(Content, <<"\n">>, [global]),<br>
List1 = lists:filter(fun(W) -> W =/= <<>> end, List0),<br>
gb_sets:from_list(List1).<br>
<br>
With the parse_transform, dialyzer complains on usage, e.g. :<br>
<br>
[warning] some_module.erl:123 the call gb_sets:add(<VALUE>,Var::{1..1<wbr>114111,{_,_,_}}) does not have an opaque term of type gb_sets:set(_) as 2nd argument<br>
<br>
Yet, of course, some_module.erl does not violate the opacity of gb_sets:set() itself.<br>
I can trick dialyzer with an expensive identity function:<br>
<br>
gb_sets:add(Value, binary_to_term(term_to_binary(<wbr>Var)))<br>
<br>
Any better idea?<br>
<br>
Paul<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
</blockquote></div><br></div>
______________________________<wbr>_________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>