Skip to content

The code rejected by Dialyzer5 but not by Fialyzer #274

@yuezato

Description

@yuezato

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}).

Dialyzer

$ 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)

Fialyzer

$ erlc +debug_info cards.erl
$ ../_build/default/bin/main.exe cards.beam
done (passed successfully)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions