diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index 93eaaa6417cb..eac79cb890e1 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -590,7 +590,8 @@ massage_type({type, Loc, 'fun', 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 + case sets:is_element({Name, length(Args0)}, Defs) andalso + erl_internal:is_type(Name, length(Args0)) of true -> %% This name for a built-in type has been overriden locally %% with a new definition. diff --git a/lib/dialyzer/test/small_SUITE_data/results/redefine_builtin_type b/lib/dialyzer/test/small_SUITE_data/results/redefine_builtin_type index e69de29bb2d1..3ea55eb1f233 100644 --- a/lib/dialyzer/test/small_SUITE_data/results/redefine_builtin_type +++ b/lib/dialyzer/test/small_SUITE_data/results/redefine_builtin_type @@ -0,0 +1,25 @@ + +redefine_builtin_type.erl:54:2: Invalid type specification for function redefine_builtin_type:foo/1. + The success typing is redefine_builtin_type:foo(1) -> 'ok' + But the spec is redefine_builtin_type:foo(my_tuple()) -> 'ok' + They do not overlap in the 1st argument + +%% %CopyrightBegin% +%% +%% SPDX-License-Identifier: Apache-2.0 +%% +%% Copyright Ericsson AB 2022-2026. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% diff --git a/lib/dialyzer/test/small_SUITE_data/src/redefine_builtin_type.erl b/lib/dialyzer/test/small_SUITE_data/src/redefine_builtin_type.erl index 9cf80cafb663..1ad1f52d0f8a 100644 --- a/lib/dialyzer/test/small_SUITE_data/src/redefine_builtin_type.erl +++ b/lib/dialyzer/test/small_SUITE_data/src/redefine_builtin_type.erl @@ -1,5 +1,26 @@ +%% %CopyrightBegin% +%% +%% SPDX-License-Identifier: Apache-2.0 +%% +%% Copyright Ericsson AB 2022-2026. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% + -module(redefine_builtin_type). --export([lookup/2, verify_mfa/1, verify_pid/1]). +-export([lookup/2, verify_mfa/1, verify_pid/1, foo/1]). +-export_type([my_map/0, my_tuple/0]). -type map() :: {atom(), erlang:map()}. @@ -22,3 +43,13 @@ verify_mfa({M, F, A}) when is_atom(M), is_atom(F), is_integer(A) -> -spec verify_pid(module()) -> 'ok'. verify_pid(Pid) when is_pid(Pid) -> ok. + +-type map(_Type) :: map(). %% shadows the builtin map type +-type my_map() :: undefined | #{atom() => string()} | '_'. + +-type tuple(_Type) :: integer(). +-type my_tuple() :: {atom()}. + +%% Should emit Dialyzer warning. +-spec foo(my_tuple()) -> ok. +foo(1) -> ok.