[erlang-questions] Dialyzer treats -opaque types different?

Ola Bäckström <>
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:

-type mytype() :: proplists:proplist() | atom().

-spec test(A :: mytype()) -> term().
test(A) ->
    case something(A) of
        true ->
        _ ->
            proplists:get_value(test, A)

-spec something(A :: mytype()) -> boolean().
something(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().
-spec something(A :: dummy:mytype()) -> boolean().
makes Dialyzer happy again. Why?
And do I have a type error or not :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130122/43cc353f/attachment.html>

More information about the erlang-questions mailing list