Open yuezato opened 5 years ago
The following code is taken from https://learnyousomeerlang.com/dialyzer#typing-functions
-module(cards). -export([kind/1, main/0]). -type suit() :: spades | clubs | hearts | diamonds. -type value() :: 1..10 | j | q | k. -type card() :: {suit(), value()}. -spec kind(card()) -> face | number. kind({_, A}) when A >= 1, A =< 10 -> number; kind(_) -> face. main() -> number = kind({spades, 7}), face = kind({hearts, k}), number = kind({rubies, 4}), face = kind({clubs, q}).
$ erl --version Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace] $ dialyzer --version Dialyzer version v4.0.1 $ dialyzer cards.erl Checking whether the PLT /Users/yuuya_uezato/.dialyzer_plt is up-to-date... yes Proceeding with analysis... cards.erl:12: Function main/0 has no local return cards.erl:15: The call cards:kind ({'rubies', 4}) breaks the contract (card()) -> 'face' | 'number' done in 0m0.17s done (warnings were emitted)
$ erlc +debug_info cards.erl $ ../_build/default/bin/main.exe cards.beam done (passed successfully)
The following code is taken from https://learnyousomeerlang.com/dialyzer#typing-functions
Dialyzer
Fialyzer