Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document compiler options warn_missing_spec and warn_missing_spec_all #2918

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 23 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,
warn_missing_spec/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, warn_missing_spec].

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

warn_missing_spec(Config) ->
Test = <<"-export([external_with_spec/0, external_no_spec/0]).

-spec external_with_spec() -> ok.
external_with_spec() -> ok.

external_no_spec() -> ok.

-spec internal_with_spec() -> ok.
internal_with_spec() -> ok.

internal_no_spec() -> ok.">>,
run(Config, [
{warn_missing_spec, Test, [warn_missing_spec],
{warnings, [{6, erl_lint, {missing_spec, {external_no_spec, 0}}}]}},
{warn_missing_spec_all, Test, [warn_missing_spec_all],
{warnings, [{6, erl_lint, {missing_spec, {external_no_spec, 0}}},
{11, erl_lint, {missing_spec, {internal_no_spec, 0}}}]}}
]).

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

Expand Down