<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Alex, Tobias,<div class=""><br class=""></div><div class="">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 class="">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(V)), although not free (it's still a remote call).</div><div class=""><br class=""></div><div class="">Paul</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 30 Jun 2017, at 15:29, Alex S. <<a href="mailto:alex0player@gmail.com" class="">alex0player@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">he is constructing it, after parse transform takes place.<br class=""><div class=""><blockquote type="cite" class=""><div class="">30 июня 2017 г., в 14:27, Tobias Lindahl <<a href="mailto:tobias.lindahl@gmail.com" class="">tobias.lindahl@gmail.com</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2017-06-25 18:56 GMT+02:00 Paul Guyot <span dir="ltr" class=""><<a href="mailto:pguyot@kallisys.net" target="_blank" class="">pguyot@kallisys.net</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br class="">
<br class="">
I do have a parse transform that replaces the body of a 0-arity function with its result, as evaluated at compile time.<br class="">
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 class="">
<br class="">
Typically, such a function would load data from a file and create a gb_sets:set() from this data.<br class="">
<br class="">
-spec f() -> gb_sets:set(unicode:unicode_<wbr class="">binary()).<br class="">
f() -><br class="">
{ok, Content} = file:read_file(?FILENAME),<br class="">
List0 = binary:split(Content, <<"\n">>, [global]),<br class="">
List1 = lists:filter(fun(W) -> W =/= <<>> end, List0),<br class="">
gb_sets:from_list(List1).<br class="">
<br class="">
With the parse_transform, dialyzer complains on usage, e.g. :<br class="">
<br class="">
[warning] some_module.erl:123 the call gb_sets:add(<VALUE>,Var::{1..<wbr class="">1114111,{_,_,_}}) does not have an opaque term of type gb_sets:set(_) as 2nd argument<br class="">
<br class="">
Yet, of course, some_module.erl does not violate the opacity of gb_sets:set() itself.<br class="">
I can trick dialyzer with an expensive identity function:<br class="">
<br class="">
gb_sets:add(Value, binary_to_term(term_to_binary(<wbr class="">Var)))<br class="">
<br class="">
Any better idea?<br class="">
<br class="">
Paul<br class="">
______________________________<wbr class="">_________________<br class="">
erlang-questions mailing list<br class="">
<a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank" class="">http://erlang.org/mailman/<wbr class="">listinfo/erlang-questions</a><br class="">
</blockquote></div><br class=""></div>
_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class=""><a href="http://erlang.org/mailman/listinfo/erlang-questions" class="">http://erlang.org/mailman/listinfo/erlang-questions</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></body></html>