josefs / Gradualizer

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

Uncaught case clause error #{'Value' => {type,0,tuple,any}} #526

Open tsloughter opened 1 year ago

tsloughter commented 1 year ago

I just updated gradualizer in https://github.com/open-telemetry/opentelemetry-erlang and tried running it. It eventually crashes with this error:

===> Uncaught error: {case_clause,#{'Value' => {type,0,tuple,any}}}
===> Stack trace to the error location:
[{typechecker,do_type_check_expr,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1676}]},
 {typechecker,type_check_expr,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1668}]},
 {typechecker,type_check_rel_op,5,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2180}]},
 {typechecker,type_check_expr,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1668}]},
 {typechecker,check_guard_expression,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4594}]},
 {typechecker,check_guard_expression,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4591}]},
 {typechecker,check_guard_expression,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4587}]},
 {typechecker,'-check_guard/2-fun-0-',2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,4601}]}]

And actually get a different error when I run it without --use_beams:

===> Uncaught error: {badkey,'Map'}
===> Stack trace to the error location:
[{erlang,map_get,
         ['Map',#{'Value' => {type,0,binary,[{integer,0,0},{integer,0,8}]}}],
         [{error_info,#{module => erl_erts_errors}}]},
 {typechecker,do_type_check_expr_in,3,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2480}]},
 {typechecker,type_check_expr_in,3,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2468}]},
 {typechecker,'-type_check_call_ty/4-lc$^0/1-0-',2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2256}]},
 {typechecker,type_check_call_ty,4,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2257}]},
 {typechecker,do_type_check_expr,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1797}]},
 {typechecker,type_check_expr,2,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,1668}]},
 {typechecker,type_check_rel_op,5,
              [{file,"/home/tristan/Devel/opentelemetry-erlang/_build/default/plugins/gradualizer/src/typechecker.erl"},
               {line,2180}]}]
RobinMorisset commented 1 year ago

Here is a simple testcase that produces the same error:

f(_V0, _V1) ->
    <<_V1:(_V2 = ok)/little-unit:119>>,
    _V2.

produces

escript: exception error: no case clause matching #{'_V0' => {type,0,any,[]},
                                           '_V1' => {type,0,any,[]}}
  in function  typechecker:do_type_check_expr/2 (src/typechecker.erl, line 1722)
  in call from typechecker:type_check_expr/2 (src/typechecker.erl, line 1714)
  in call from typechecker:do_type_check_expr_in/3 (src/typechecker.erl, line 2523)
  in call from typechecker:type_check_expr_in/3 (src/typechecker.erl, line 2514)
  in call from typechecker:type_check_block_in/3 (src/typechecker.erl, line 3565)
  in call from typechecker:check_clause/5 (src/typechecker.erl, line 4027)
  in call from typechecker:check_reachable_clauses/7 (src/typechecker.erl, line 3937)
  in call from typechecker:check_clauses/5 (src/typechecker.erl, line 3907)