Skip to content

Commit

Permalink
fixup! dialyzer: Introduce nominal types
Browse files Browse the repository at this point in the history
  • Loading branch information
jhogberg authored and lucioleKi committed Nov 21, 2024
1 parent 17402ff commit 54eda11
Show file tree
Hide file tree
Showing 248 changed files with 4,739 additions and 9 deletions.
19 changes: 19 additions & 0 deletions lib/dialyzer/test/behaviour_SUITE_data/results/callbacks_and_specs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2022. 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%
%%

my_callbacks_wrong.erl:26:2: The return type #state{parent::pid(),status::'closed' | 'init' | 'open',subscribe::[{pid(),integer()}],counter::integer()} in the specification of callback_init/1 has nothing in common with {'ok',_}, which is the expected return type for the callback of the my_behaviour behaviour
my_callbacks_wrong.erl:28:1: The inferred return type of callback_init/1 (#state{parent::pid(),status::'init',subscribe::[],counter::1}) has nothing in common with {'ok',_}, which is the expected return type for the callback of the my_behaviour behaviour
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2020. 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%
%%

gen_event_incorrect_return.erl:16:1: The inferred return type of init/1 ('error') has nothing in common with {'error',_} | {'ok',_} | {'ok',_,'hibernate'}, which is the expected return type for the callback of the gen_event behaviour
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2022. 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%
%%

gen_server_incorrect_args.erl:3:2: Undefined callback function handle_cast/2 (behaviour gen_server)
gen_server_incorrect_args.erl:3:2: Undefined callback function init/1 (behaviour gen_server)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2020. 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%
%%

gen_server_missing_callbacks.erl:3:2: Undefined callback function handle_cast/2 (behaviour gen_server)
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2022-2022. 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%
%%

gen_server_not_exported.erl:14:1: Callback function init/1 exists but is not exported (behaviour gen_server)
gen_server_not_exported.erl:23:1: Callback function handle_cast/2 exists but is not exported (behaviour gen_server)
19 changes: 19 additions & 0 deletions lib/dialyzer/test/behaviour_SUITE_data/results/otp_6221
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2009-2022. 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%
%%
19 changes: 19 additions & 0 deletions lib/dialyzer/test/behaviour_SUITE_data/results/sample_behaviour
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2022. 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%
%%

sample_callback_wrong.erl:16:1: The inferred return type of sample_callback_2/0 (42) has nothing in common with atom(), which is the expected return type for the callback of the sample_behaviour behaviour
sample_callback_wrong.erl:17:1: The inferred return type of sample_callback_3/0 ('fair') has nothing in common with 'fail' | {'ok',1..255}, which is the expected return type for the callback of the sample_behaviour behaviour
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2022. 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%
%%

incorrect_args_callback.erl:12:1: The inferred type for the 2nd argument of bar/2 ('yes') has nothing in common with [any()], which is expected type for this argument in the callback of the correct_behaviour behaviour
incorrect_return_callback.erl:9:1: The inferred return type of foo/0 ('error') has nothing in common with 'no' | 'yes', which is the expected return type for the callback of the correct_behaviour behaviour
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2021. 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%
%%

supervisor_incorrect_return.erl:14:1: The inferred return type of init/1 ({'ok',{{'one_against_one',0,1},[{_,_,_,_,_,_},...]}}) has nothing in common with 'ignore' | {'ok',{{'one_for_all',non_neg_integer(),pos_integer()} | {'one_for_one',non_neg_integer(),pos_integer()} | {'rest_for_one',non_neg_integer(),pos_integer()} | {'simple_one_for_one',non_neg_integer(),pos_integer()} | #{'auto_shutdown'=>'all_significant' | 'any_significant' | 'never', 'intensity'=>non_neg_integer(), 'period'=>pos_integer(), 'strategy'=>'one_for_all' | 'one_for_one' | 'rest_for_one' | 'simple_one_for_one'},[{_,{atom(),atom(),'undefined' | [any()]},'permanent' | 'temporary' | 'transient','brutal_kill' | 'infinity' | non_neg_integer(),'supervisor' | 'worker','dynamic' | [atom()]} | #{'id':=_, 'start':={atom(),atom(),'undefined' | [any()]}, 'modules'=>'dynamic' | [atom()], 'restart'=>'permanent' | 'temporary' | 'transient', 'shutdown'=>'brutal_kill' | 'infinity' | non_neg_integer(), 'significant'=>boolean(), 'type'=>'supervisor' | 'worker'}]}}, which is the expected return type for the callback of the supervisor behaviour
19 changes: 19 additions & 0 deletions lib/dialyzer/test/behaviour_SUITE_data/results/undefined_callbacks
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2020. 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%
%%

undefined_beh_callback.erl:5:2: Callback info about the undefined_behaviour behaviour is not available
19 changes: 19 additions & 0 deletions lib/dialyzer/test/behaviour_SUITE_data/results/vars_in_beh_spec
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2011-2020. 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%
%%

vars_in_beh_spec.erl:3:2: Undefined callback function handle_call/3 (behaviour gen_server)
vars_in_beh_spec.erl:3:2: Undefined callback function handle_cast/2 (behaviour gen_server)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2010-2020. 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%
%%

t1.erl:16:3: Call to missing or unexported function t2:t2/1
t2.erl:13:3: Call to missing or unexported function t1:t3/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2009-2022. 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%
%%
55 changes: 46 additions & 9 deletions lib/dialyzer/test/dialyzer_common.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,19 @@ check(TestCase, Opts, Dir, OutDir) ->
_ ->
case file:open(NewResFile,[?output_file_mode]) of
{ok, OutFile} ->
file:write(OutFile, [$\n, unicode:characters_to_binary(Warns)]),
file:write(OutFile, [license_header(), "\n\n"]),
file:write(OutFile, [unicode:characters_to_binary(Warns)]),
file:close(OutFile);
Other -> erlang:error(Other)
end
end,
case file_utils:diff(NewResFile, OldResFile) of
'same' -> file:delete(NewResFile),
'same';
{'differ', List} -> escape_strings({'differ', TestCase, List})
end
case compare_results(TestCase, NewResFile, OldResFile) of
same ->
file:delete(NewResFile),
same;
{differ, _, _}=Diff ->
Diff
end
catch
Kind:Error:Stacktrace -> {'dialyzer crashed', Kind, Error, Stacktrace}
end.
Expand Down Expand Up @@ -208,9 +211,18 @@ create_all_suites() ->
Suites = get_suites(Cwd),
lists:foreach(fun create_suite/1, Suites).

escape_strings({differ, TestCase, List}) ->
Escaped = [{T, L, xmerl_lib:export_text(S)} || {T, L, S} <- List],
{differ, TestCase, lists:keysort(2, Escaped)}.
compare_results(TestCase, NewResFile, OldResFile) ->
maybe
{'differ', List} ?= file_utils:diff(NewResFile, OldResFile),
[_|_] ?= Escaped = [{T, L, xmerl_lib:export_text(S)}
|| {T, L, S} <- List,
not lists:prefix("%", S),
S =/= "\n"],
{differ, TestCase, lists:keysort(2, Escaped)}
else
same -> same;
[] -> same
end.

-spec get_suites(file:filename()) -> [string()].

Expand Down Expand Up @@ -391,3 +403,28 @@ write_testcases(OutputFile, [TestCase| Rest]) ->
write_testcases(OutputFile, Rest);
write_testcases(_OutputFile, []) ->
ok.

license_header() ->
%% Dummy license header to keep the line numbering in sync with the files on
%% disk.
"""
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB XXXX-YYYY. 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%
%%
""".
19 changes: 19 additions & 0 deletions lib/dialyzer/test/extra_return_SUITE_data/results/extra_return
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2022-2022. 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%
%%

extra_return.erl:7:2: The specification for extra_return:t1/0 states that the function might also return 'other' but the inferred return is boolean()
Loading

0 comments on commit 54eda11

Please sign in to comment.