Skip to content

Commit

Permalink
Document previously hidden (though very useful) compiler options
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Dec 9, 2020
1 parent 810d679 commit ce61a16
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/compiler/doc/src/compile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,20 @@ module.beam: module.erl \
fallbacks by accident. Use this option to turn off this kind of
warnings.</p>
</item>

<tag><c>warn_missing_spec</c></tag>
<item>
<p>By default, warnings are not emitted when a specification
(or contract) for an exported function is not given. Use this
option to turn on this kind of warning.</p>
</item>

<tag><c>warn_missing_spec_all</c></tag>
<item>
<p>By default, warnings are not emitted when a specification
(or contract) for an exported or unexported function is not
given. Use this option to turn on this kind of warning.</p>
</item>
</taglist>

<p>Another class of warnings is generated by the compiler
Expand Down
18 changes: 16 additions & 2 deletions lib/stdlib/test/erl_lint_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
otp_14285/1, otp_14378/1,
external_funs/1,otp_15456/1,otp_15563/1,
unused_type/1,removed/1, otp_16516/1,
inline_nifs/1]).
inline_nifs/1,
compile_options/1]).

suite() ->
[{ct_hooks,[ts_install_cth]},
Expand All @@ -93,7 +94,7 @@ all() ->
record_errors, otp_11879_cont, non_latin1_module, otp_14323,
stacktrace_syntax, otp_14285, otp_14378, external_funs,
otp_15456, otp_15563, unused_type, removed, otp_16516,
inline_nifs].
inline_nifs, compile_options].

groups() ->
[{unused_vars_warn, [],
Expand Down Expand Up @@ -4448,6 +4449,19 @@ inline_nifs(Config) ->
{warnings,[{2,erl_lint,nif_inline}]}}],
[] = run(Config, Ts).

compile_options(Config) ->
WOkay = get_compilation_result(Config, "warn_missing_spec_ok", [warn_missing_spec]),
[] = WOkay,

WError = get_compilation_result(Config, "warn_missing_spec_error", [warn_missing_spec]),
[_] = WError,

WAllOkay = get_compilation_result(Config, "warn_missing_spec_all_ok", [warn_missing_spec_all]),
[] = WAllOkay,

WAllError = get_compilation_result(Config, "warn_missing_spec_all_error", [warn_missing_spec_all]),
[_] = WAllError.

format_error(E) ->
lists:flatten(erl_lint:format_error(E)).

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-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%
%%
-module(erlc_test_warn_missing_spec_all_error).

-export([external/0]).

external() -> internal().

-spec internal() -> ok.
internal() -> ok.
28 changes: 28 additions & 0 deletions lib/stdlib/test/erl_lint_SUITE_data/warn_missing_spec_all_ok.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-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%
%%
-module(erlc_test_warn_missing_spec_all_ok).

-export([external/0]).

-spec external() -> ok.
external() -> internal().

-spec internal() -> ok.
internal() -> ok.
27 changes: 27 additions & 0 deletions lib/stdlib/test/erl_lint_SUITE_data/warn_missing_spec_error.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-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%
%%
-module(erlc_test_warn_missing_spec_error).

-export([external/0]).

external() -> internal().

-spec internal() -> ok.
internal() -> ok.
27 changes: 27 additions & 0 deletions lib/stdlib/test/erl_lint_SUITE_data/warn_missing_spec_ok.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-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%
%%
-module(erlc_test_warn_missing_spec_ok).

-export([external/0]).

-spec external() -> ok.
external() -> internal().

internal() -> ok.

0 comments on commit ce61a16

Please sign in to comment.