Gradualizer
Gradualizer copied to clipboard
crash with record union type with same record name
gradualizing module m2 results in a crash
(The issue is with type rec_t/0 which is a union of record type rec from the local module and a remote type which represents a record type with the same name.)
-module(m2).
-export([f/0]).
-type rec_t() :: m1:rec_v1() | rec_v2().
-record(rec, {
f1,
f2 = default}).
-type(rec_v2() :: #rec{}).
-spec f() -> rec_t().
f() ->
#rec{f1 = <<"">>}.
-module(m1).
-record(rec, {f1}).
-type(rec_v1() :: #rec{}).
-export_type([rec_v1/0]).
I get the below crash
escript: exception error: bad generator
{env,
#{{f,0} =>
[{type,
{13,8},
bounded_fun,
[{type,
{13,8},
'fun',
[{type,{13,8},product,[]},
{user_type,{13,14},rec_t,[]}]},
[]]}]},
#{},#{},
#{module => m2,
records =>
#{rec =>
[{typed_record_field,
{record_field,0,{atom,0,f1},{atom,{8,5},undefined}},
{type,0,any,[]}},
{typed_record_field,
{record_field,0,{atom,0,f2},{atom,{9,10},default}},
{type,0,any,[]}}]},
types =>
#{{rec_t,0} =>
{[],
{type,0,union,
[{remote_type,0,
[{atom,{5,18},m1},{atom,{5,21},rec_v1},[]]},
{user_type,0,rec_v2,[]}]}},
{rec_v2,0} => {[],{type,0,record,[{atom,0,rec}]}}}},
false,false,true,
[{clauses_controls,true}],
30,
[{type,
{13,8},
bounded_fun,
[{type,
{13,8},
'fun',
[{type,{13,8},product,[]},{user_type,{13,14},rec_t,[]}]},
[]]}]}
in function typechecker:'-union_var_binds/2-lc$^1/1-0-'/1 (src/typechecker.erl, line 4859)
in call from typechecker:union_var_binds/2 (src/typechecker.erl, line 4859)
in call from typechecker:do_type_check_expr_in/3 (src/typechecker.erl, line 2394)
in call from typechecker:type_check_expr_in/3 (src/typechecker.erl, line 2250)
in call from typechecker:check_clause/5 (src/typechecker.erl, line 3536)
in call from typechecker:'-check_clauses/5-fun-0-'/4 (src/typechecker.erl, line 3441)
in call from lists:foldl/3 (lists.erl, line 1267)
in call from typechecker:check_clauses/5 (src/typechecker.erl, line 3439)
Gradualizer version commit a72e7f0b7e55f235fdaa944340a13e0e41bc5ee3
Hi, @gomoripeti!
Thanks for the report. I checked the examples you provide with the current master branch (https://github.com/josefs/Gradualizer/commit/f647ae76b1510f6d3b367fec06dc2d68c7ede88c) and cannot reproduce the problem - no crash occurs. Could you confirm if the problem is solved for you, too?