[erlang-questions] Dialyzer Error: "Analysis failed with error"
Kostis Sagonas
kostis@REDACTED
Sat Jun 25 09:32:15 CEST 2011
David Mercer wrote:
> Inspired by
> http://www.erlang-factory.com/upload/presentations/347/Kostis.pdf, I
> decided to give Dialyzer a go. The first file I tried it on, however,
> failed with a rather unhelpful error. After trimming a few thousand
> lines, I’ve got it down to the following minimal case:
>
> -module(dialyzer_test).
>
> -export([test/1]).
>
> -record(rec1, {f1}).
> -record(rec2, {f2}).
>
> -type rec1(T) :: #rec1{f1 :: T}.
> -type rec2(T) :: #rec2{f2 :: T}.
>
> -spec test(rec2(rec1(A))) -> A.
>
> test(#rec2{f2 = #rec1{f1 = X}}) -> X.
>
> The Dialyzer error is:
>
> dialyzer: Analysis failed with error: Illegal declaration of #rec2{f2}
>
> Can anyone explain to me what’s wrong with my types and spec? Please
> advise. Thank-you.
In principle there is nothing wrong with your types and specs. It seems
you have hit a limitation (bug?) which makes parametric types involving
records not handled properly by Erlang/OTP. (Record expressions are
nasty, because they are handled by the preprocessor.) I'll try to see
what can be done about it for R14B04.
In the meantime, you can bypass this error by declaring the type you
want as follows:
-type rec2rec1(T) :: {rec2, rec1(T)}.
-spec test(rec2rec1(A)) -> A.
Far from ideal, I know...
Thanks for the minimal test case!
Kostis
More information about the erlang-questions
mailing list