Skip to content

Commit

Permalink
dialyzer: Handle definition of type product/0
Browse files Browse the repository at this point in the history
Analyzing a module that defines the type `product/0` could crash
Dialyzer. This bug was introduced in 4d08fc9.

Fixes #7584
  • Loading branch information
bjorng committed Aug 29, 2023
1 parent 9d74808 commit a8f5854
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/dialyzer/src/dialyzer_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,13 @@ massage_forms([H | T], Defs) ->
massage_forms([], _Defs) ->
[].

massage_type({type, Loc, 'fun',
[{type, ArgsLoc, product, ArgTypes}, Ret0]},
Defs) ->
%% We must make sure that we keep the built-in `product` type here.
Args = {type, ArgsLoc, product, massage_type_list(ArgTypes, Defs)},
Ret = massage_type(Ret0, Defs),
{type, Loc, 'fun', [Args, Ret]};
massage_type({type, Loc, Name, Args0}, Defs) when is_list(Args0) ->
case sets:is_element({Name, length(Args0)}, Defs) of
true ->
Expand Down
13 changes: 13 additions & 0 deletions lib/dialyzer/test/small_SUITE_data/src/test_product_app.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-module(test_product_app).
-export([zero/0, one/1]).

-type mfa() :: integer().
-type product() :: binary().

-spec zero() -> any().
zero() ->
ok.

-spec one(mfa()) -> mfa().
one(I) when is_integer(I) ->
I * 42.

0 comments on commit a8f5854

Please sign in to comment.