[erlang-bugs] Problem with nested opaque types

Jesper Larsson erlang@REDACTED
Thu Oct 18 19:39:26 CEST 2012


Hi,

This seems related to http://erlang.org/pipermail/erlang-bugs/2010-July/001904.html which is allegedly fixed, but the problem described below still exists. I have Erlang R15B02 and Dialyzer reports version v2.5.2. (I couldn't find how to map these numbers to each other.)

I boiled it down to this:

%% ======== exporter.erl
-module(exporter).
-export([traverser/1]).
-export_type([trav/0, tree/0]).

-opaque tree() :: {tuple()}.
-opaque trav() :: {non_neg_integer(), tree()}.

-spec traverser(tree()) -> trav().
traverser(Rftree) ->
   {1, Rftree}.

%% ======== importer.erl
-module(importer).
-export([foo/1]).

-spec foo(exporter:tree()) -> float().
foo(Rftree) ->
   cwl(exporter:traverser(Rftree)).

-spec cwl(exporter:trav()) -> float().
cwl(_Trav) -> 0.0.


I get the following Dialyzer errors:

importer.erl:5: Function foo/1 has no local return
importer.erl:6: The call importer:cwl(exporter:trav()) contains an opaque term as 1st argument when an opaque term of type exporter:trav() is expected
importer.erl:8: Invalid type specification for function importer:cwl/1. The success typing is (exporter:trav()) -> float()

So it complains about the type specification for cwl but gives me exactly the same as success typing. I got around the problems with the following workaround, which I feel should not be necessary, or at least the error message should be nicer.

%% ======== workaround exporter.erl
-module(exporter).
-export([traverser/1]).
-export_type([trav/0, tree/0]).

-define(tree_def, {tuple()}).
-opaque tree() :: ?tree_def.
-opaque trav() :: {non_neg_integer(), ?tree_def}.

-spec traverser(tree()) -> trav().
traverser(Rftree) ->
   {1, Rftree}.


/Jesper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20121018/b77cc482/attachment.htm>


More information about the erlang-bugs mailing list