josefs / Gradualizer

A Gradual type system for Erlang
MIT License
609 stars 35 forks source link

Exhaustivity checking issue #562

Open erszcz opened 3 months ago

erszcz commented 3 months ago

The following module, modelled after Gradualizer code dealing with type() instances:

-module(exhaustivity_issue).

-export([g/1]).

-include("include/gradualizer.hrl").

-type simple_type() :: {type, list | nonempty_list, [a | simple_type()]}
                     | {type, atom, {b}}.

-spec g(simple_type()) -> b | simple_type().
g({type, list, []}) ->
    b;
g({type, list, [a]}) ->
    b;
g({type, nonempty_list, []}) ->
    b;
g({type, nonempty_list, [a]}) ->
    b;
g({type, list, [a, SimpleTy]}) ->
    ?assert_type(SimpleTy, simple_type());
g({type, atom, {_InnerNode}}) ->
    b.

Fails with:

$ ./bin/gradualizer exhaustivity_issue.erl
exhaustivity_issue.erl: Nonexhaustive patterns on line 11 at column 1
Example values which are not covered:
    {type, nonempty_list, [a]}

Gradualizer commit: 81385f6