« Erlangでのプロファイリング | Main | Erlang の smart_exception で例外が変になる »

Thursday, June 14, 2007

Erlang R11B-5 リリース

Erlang R11B-5 がリリースされた.

詳細はリリースノートを参照.
今回のリリースで一番うれしいと思うのが,dialyzerの改良.
まだデフォルトでは無効になっているようだけど,オプションを指定すれば,関数の呼び出しの型チェックが行えるようになる.

R11B-4 までは,関数の型を推測することはできたものの,エラーチェックには生かせていなかった.
R11B-5 では,dialyzer に --succ_typeing オプションを渡すことで,エラーチェックをすることが出来るようになった.


-module(test).
-export([test_error/0, test_ok/0]).

test_error() ->
test(1).

test_ok() ->
test([1]).

test(N) when is_list(N) ->
ok.


というコードを想定する.

test(N) はリストしか受け取らないので,それ以外が渡された場合は function_cause エラーが起きてしまう.

今までは


$ dialyzer -c test.erl
Checking whether the initial PLT exists and is up-to-date... yes
Proceeding with analysis... done (passed successfully)

のようにエラーチェックが出来なかったのだけど,R11B-5 では以下のようにエラーチェックが可能になった.

$ dialyzer --succ_typings -c test.erl
Checking whether the initial PLT exists and is up-to-date... yes
Proceeding with analysis...
test.erl:5: Function test_error/0 has no local return
test.erl:6: The call test:test(1) will fail since the signature is test:test/1 :: (([1,...]) -> 'ok')
done (warnings were emitted)

ちなみに,型の推測は typer コマンドで出来る.

$ typer test.erl
Processing file: "test.erl"
Saved as: "./typer_ann/test.ann.erl"
$ cat ./typer_ann/test.ann.erl

-module(test).
-export([test_error/0, test_ok/0]).

%% @typer_spec test_error/0 :: (() -> none())
test_error() ->
test(1).

%% @typer_spec test_ok/0 :: (() -> 'ok')
test_ok() ->
test([1]).

%% @typer_spec test/1 :: (([1,...]) -> 'ok')
test(N) when is_list(N) ->
ok.


make時に自動でチェックするようにすると便利そう.

|

« Erlangでのプロファイリング | Main | Erlang の smart_exception で例外が変になる »

Comments

The comments to this entry are closed.

TrackBack


Listed below are links to weblogs that reference Erlang R11B-5 リリース:

« Erlangでのプロファイリング | Main | Erlang の smart_exception で例外が変になる »