From a8f585426f47ecf533b787464aef424857791ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 28 Aug 2023 13:54:16 +0200 Subject: [PATCH] dialyzer: Handle definition of type product/0 Analyzing a module that defines the type `product/0` could crash Dialyzer. This bug was introduced in 4d08fc95830b650d. Fixes #7584 --- lib/dialyzer/src/dialyzer_utils.erl | 7 +++++++ .../test/small_SUITE_data/src/test_product_app.erl | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/dialyzer/test/small_SUITE_data/src/test_product_app.erl diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index b920d22b309b..4df458c7b658 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -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 -> diff --git a/lib/dialyzer/test/small_SUITE_data/src/test_product_app.erl b/lib/dialyzer/test/small_SUITE_data/src/test_product_app.erl new file mode 100644 index 000000000000..2115c62a1b38 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/test_product_app.erl @@ -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.