<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_<wbr>binary()).<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..<wbr>1114111,{_,_,_}}) 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">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</blockquote></div><br></div>