Skip to content

Commit

Permalink
Merge pull request #517 from erszcz/dont-discard-annotation-in-instan…
Browse files Browse the repository at this point in the history
…tiate-2

Don't discard annotation in instantiate/2
  • Loading branch information
erszcz authored Mar 3, 2023
2 parents d2ea320 + 7c082b7 commit fc90bb8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/typechecker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3622,7 +3622,7 @@ instantiate({var, _, TyVar}, Map) ->
end;
instantiate(T = ?type(_), Map) ->
{T, maps:new(), Map};
instantiate(?type(Ty, Args), Map) ->
instantiate({type, P, Ty, Args}, Map) ->
%% TODO: Ugly, but until we have better support for union args to intersection-typed funs,
%% it fixes the type-check error.
{NewArgs, Set, NewMap} = case Args of
Expand All @@ -3631,8 +3631,7 @@ instantiate(?type(Ty, Args), Map) ->
_ when is_list(Args) ->
instantiate_inner(?assert_type(Args, list()), Map)
end,
%% TODO: Another case of union arg to an intersection-typed fun :(
{type(Ty, NewArgs), Set, NewMap};
{type(Ty, P, NewArgs), Set, NewMap};
instantiate(T = {Tag, _,_}, Map)
when Tag == integer orelse Tag == atom orelse Tag == char ->
{T, maps:new(), Map};
Expand Down Expand Up @@ -5313,6 +5312,10 @@ type_of_bin_element({bin_element, _P, Expr, _Size, Specifiers}, OccursAs) ->
type(Name, Args) ->
{type, erl_anno:new(0), Name, Args}.

-spec type(_, _, _) -> type().
type(Name, Anno, Args) ->
{type, Anno, Name, Args}.

%% Helper to create a type, typically a normalized type
-spec type(atom()) -> type().
type(top) ->
Expand Down
3 changes: 1 addition & 2 deletions src/typelib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
reduce_type/3]).
-export_type([constraint/0, function_type/0, printable_type/0]).

-type af_constraint() :: gradualizer_type:af_constraint().
-type anno() :: erl_anno:anno().
-type type() :: gradualizer_type:abstract_type().

Expand Down Expand Up @@ -203,7 +202,7 @@ annotate_user_type_(Filename, {type, Anno, record, RecName = [_]}) ->
RecName = ?assert_type(RecName, [gradualizer_type:af_atom(), ...]),
%% Annotate local record type
{type, erl_anno:set_file(Filename, Anno), record, RecName};
annotate_user_type_(Filename, {type, Anno, T, Params} = OuterT) when is_list(Params) ->
annotate_user_type_(Filename, {type, Anno, T, Params}) when is_list(Params) ->
{type, Anno, T, [ annotate_user_types(Filename, Param) || Param <- Params ]};
annotate_user_type_(Filename, {ann_type, Anno, [Var, Type]}) ->
%% We match Var :: af_anno() and Type :: type() above.
Expand Down

0 comments on commit fc90bb8

Please sign in to comment.