Skip to content

Commit

Permalink
Record update missing fields fix (#314)
Browse files Browse the repository at this point in the history
Record update missing fields fix for type any
  • Loading branch information
Francois Brodeur authored Feb 18, 2021
1 parent 2108ccb commit c83a9b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/typechecker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ do_type_check_expr(Env, {record, Anno, Expr, Record, Fields}) ->
RecTy = {type, erl_anno:new(0), record, [{atom, erl_anno:new(0), Record}]},
{VB1, Cs1} = type_check_expr_in(Env, RecTy, Expr),
Rec = get_record_fields(Record, Anno, Env#env.tenv),
{VB2, Cs2} = type_check_fields(Env, Rec, Fields),
{VB2, Cs2} = type_check_fields_for_update(Env, Rec, Fields),
{RecTy, union_var_binds(VB1, VB2, Env#env.tenv), constraints:combine(Cs1, Cs2)};
do_type_check_expr(Env, {record, Anno, Record, Fields}) ->
RecTy = {type, erl_anno:new(0), record, [{atom, erl_anno:new(0), Record}]},
Expand Down Expand Up @@ -1703,6 +1703,9 @@ create_fun_type(Arity, RetTy) when is_integer(Arity) ->
ParTys = lists:duplicate(Arity, type(any)),
type('fun', [type(product, ParTys), RetTy]).

type_check_fields_for_update(Env, Rec, Fields) ->
type_check_fields(Env, Rec, Fields, should_not_be_inspected).

type_check_fields(Env, Rec, Fields) ->
UnAssignedFields = get_unassigned_fields(Fields, Rec),
type_check_fields(Env, Rec, Fields, UnAssignedFields).
Expand Down
10 changes: 10 additions & 0 deletions test/should_pass/records.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ record_as_tuple(R) ->

-record(rec_any, {f}).
f(#rec_any{f = F} = R) -> F.

-record(nospec_update_bug, {
a :: integer(),
b :: integer()
}).

nospec_update_bug(Rec) ->
Rec#nospec_update_bug{
b = 0
}.

0 comments on commit c83a9b4

Please sign in to comment.