summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Larsson <lukas@erlang.org>2021-04-12 09:03:45 +0200
committerGitHub <noreply@github.com>2021-04-12 09:03:45 +0200
commitae925bed11073e2d65641b6ccb9f7f42141077fe (patch)
tree4c5b47b38e7ac32aed3c24076cf6472c7990031e
parent3a90d1237a9cbe894c838c8b5c405bc96e013737 (diff)
parent5ff36749dd6953dd989bdc7b4912d5248e671807 (diff)
downloaderlang-ae925bed11073e2d65641b6ccb9f7f42141077fe.tar.gz
Merge pull request #4716 from erszcz/edoc-multiple-specs-fix
EDoc: suggest {preprocess, true} when redundant spec assertion fails
-rw-r--r--lib/edoc/src/edoc.erl3
-rw-r--r--lib/edoc/src/edoc.hrl3
-rw-r--r--lib/edoc/src/edoc_extract.erl15
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/edoc/src/edoc.erl b/lib/edoc/src/edoc.erl
index a811037b5f..6ec5565fb0 100644
--- a/lib/edoc/src/edoc.erl
+++ b/lib/edoc/src/edoc.erl
@@ -77,7 +77,8 @@
exports :: ordset(function_name()),
attributes :: ordset({atom(), term()}),
records :: [{atom(), [{atom(), term()}]}],
- encoding :: epp:source_encoding()}.
+ encoding :: epp:source_encoding(),
+ file :: file:filename()}.
%% Module information.
-type env() :: #env{}.
diff --git a/lib/edoc/src/edoc.hrl b/lib/edoc/src/edoc.hrl
index 9365d2ea5b..82d1fe932f 100644
--- a/lib/edoc/src/edoc.hrl
+++ b/lib/edoc/src/edoc.hrl
@@ -50,7 +50,8 @@
exports = [],
attributes = [],
records = [],
- encoding = latin1}).
+ encoding = latin1,
+ file}).
-record(env, {module = [],
root = "",
diff --git a/lib/edoc/src/edoc_extract.erl b/lib/edoc/src/edoc_extract.erl
index 75df6637ab..cef5e55703 100644
--- a/lib/edoc/src/edoc_extract.erl
+++ b/lib/edoc/src/edoc_extract.erl
@@ -328,7 +328,8 @@ get_module_info(Forms, File) ->
exports = ordsets:intersection(Exports, Functions),
attributes = Attributes,
records = Records,
- encoding = Encoding}.
+ encoding = Encoding,
+ file = File}.
get_list_keyval(Key, L) ->
case lists:keyfind(Key, 1, L) of
@@ -483,9 +484,19 @@ insert_specs(As, Ss, Mod) ->
Specs = maps:from_list(SpecList),
%% Assert that we've not skipped redundant specs for the same {Fun, Arity}.
%% This should never happen, as such a module would not compile.
- true = length(SpecList) == maps:size(Specs),
+ case length(SpecList) == maps:size(Specs) of
+ true -> ok;
+ false -> error_redundant_specs(Mod, SpecList, Specs)
+ end,
insert_specs_(ModName, As, Specs).
+error_redundant_specs(Mod, SpecList, Specs) ->
+ [{RedundantMFA, [Form]} | _] = lists:sort(SpecList) -- lists:sort(maps:to_list(Specs)),
+ {_, Line, _, _} = erl_syntax:revert(Form),
+ {_, F, A} = RedundantMFA,
+ edoc_report:error(Line, {Mod#module.file, {F, A}}, "Redundant -spec attribute found. Try setting {preprocess, true}."),
+ erlang:exit({redundant_spec, RedundantMFA}).
+
insert_specs_(_, [], _) -> [];
insert_specs_(ModName, [#entry{} = A | As], Specs) ->
#entry{name = {F, Arity}, data = {Cs, Cbs, _, Ts, Rs}} = A,