2017-03-23 5 views
0

で抽象違反が発生し、不透明なタイプを取得できません不透明な型を定義モジュールです:は、ここで透析器

-module(a). 
-export([people/0, get_names/1]). 
-export_type([person/0]). 

-opaque person()  :: {person, first_name()}. 
-type first_name() :: string(). 

-spec people() -> People when 
     People :: [person()]. 

people() -> 
    [{person, "Joe"}, {person, "Cindy"}]. 

-spec get_names(People) -> Names when 
     People  :: [person()], 
     Names  :: [string()]. 

get_names(Ps) -> 
    get_names(Ps, []). 

get_names([ {person, Name} | Ps ], Names) -> 
    get_names(Ps, [Name|Names]); 
get_names([], Names) -> 
    lists:reverse(Names). 

そして、ここではその周りmucks人()タイプの内部モジュールです私は透析器が文句を言うことが期待

~/erlang_programs$ dialyzer b.erl 
    Checking whether the PLT /Users/7stud/.dialyzer_plt is up-to-date... yes 
    Proceeding with analysis... 
Unknown functions: 
    a:people/0 
done in 0m0.49s 
done (passed successfully) 

-module(b). 
-export([do/0]). 

-spec do() -> Name when 
     Name :: string(). 

do() -> 
    [{person, Name} | _People] = a:people(), 
    Name. 

とダイアライザー。

答えて

1

これは動作します:

$ dialyzer a.erl b.erl 

Checking whether the PLT /Users/7stud/.dialyzer_plt is up-to-date... yes 
    Proceeding with analysis... 
b.erl:7: Function do/0 has no local return 
b.erl:8: The attempt to match a term of type a:person() against the pattern 
{'person', Name} breaks the opaqueness of the term 
done in 0m0.52s 
done (warnings were emitted) 
+1

ダイアライザーは、種類のルックアップテーブル( '.plt')を使用しています。 'Unknown functions:' 'a:people/0'という警告は、モジュール' a'が 'b'をチェックする際にダイアライザに知られていないことを示しています。この問題を回避するには、CLIでチェックする必要があるすべてのモジュールを指定します。モジュールから '.plt'をビルドすることもできます(http://erlang.org/doc/apps/dialyzer/dialyzer_chapter.html)。基本的には、初期の '.plt'を作成してから' a'を追加します。そして 'b'をチェックするときに' .plt'を使うことができます。 – evnu

関連する問題