josefs / Gradualizer

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

Crash with `Uncaught error: {case_clause, ..` in `typechecker:do_type_check_expr/2` #531

Closed ilya-klyuchnikov closed 1 year ago

ilya-klyuchnikov commented 1 year ago

A repro:

-module(gradualizer_repro2).

-export([foo/2]).

-spec foo(List1, List2) -> List2 when
  List1 :: [Int],
  List2 :: [Int|{Int,Int}],
  Int :: integer().
foo([], Acc) ->
  Acc;
foo([H | T], []) ->
  foo(T, [H]);
foo([H | T], [HA | TA]) when is_integer(HA), H == HA + 1 ->
  foo(T, [{HA, H} | TA]);
foo([H | T], [{HAB, HAE} | TA]) when H == HAE + 1 ->
  foo(T, [{HAB, H} | TA]);
foo([H | T], Acc) ->
  foo(T, [H | Acc]).
===> Uncaught error: {case_clause,#{'HA' => {type,0,integer,[]}}}
===> Stack trace to the error location:
[{typechecker,do_type_check_expr,2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1695}]},
 {typechecker,type_check_expr,2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1687}]},
 {typechecker,type_check_rel_op,5,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2199}]},
 {typechecker,type_check_expr,2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1687}]},
 {typechecker,check_guard_expression,2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4613}]},
 {typechecker,'-check_guard/2-fun-0-',2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4620}]},
 {lists,foldl_1,3,[{file,"lists.erl"},{line,1355}]},
 {typechecker,check_guard,2,
              [{file,"/Users/ilyaklyuchnikov/code/gr-rebar3/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4619}]}]