[erlang-questions] Dialyzer treats -opaque types different?
Ola Bäckström
Ola.Backstrom@REDACTED
Tue Jan 22 16:10:34 CET 2013
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.
Now I'm facing differences ... why? :)
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:
-module(dummy).
-export([test/1]).
-type mytype() :: proplists:proplist() | atom().
-spec test(A :: mytype()) -> term().
test(A) ->
case something(A) of
true ->
throw(up);
_ ->
proplists:get_value(test, A)
end.
-spec something(A :: mytype()) -> boolean().
something(A) ->
is_atom(A).
Dialyzer reports no issue on the above snippet.
If I change the type to opaque in line 3:
-opaque mytype() :: proplists:proplist() | atom().
then Dialyzer reports:
dummy.erl:6: Function test/1 has no local return
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
Then adding module name to the type reference in the 2 function specs:
-spec test(A :: dummy:mytype()) -> term().
and
-spec something(A :: dummy:mytype()) -> boolean().
makes Dialyzer happy again. Why?
And do I have a type error or not :)
/Ola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130122/43cc353f/attachment.htm>
More information about the erlang-questions
mailing list