Permalink
Browse files

Rewrite qlc_pt:no_duplicates/5

Duplicate errors need to be compared without taking into account column
numbers.
  • Loading branch information...
1 parent 2d1c3d0 commit 22027c4aa9670d6bdedf0370dc98ad4c9ce3ec89 @nox nox committed Aug 25, 2012
Showing with 23 additions and 8 deletions.
  1. +23 −8 lib/stdlib/src/qlc_pt.erl
@@ -170,14 +170,15 @@ mforms(Tag, L) ->
no_duplicates(Forms, Errors, Warnings0, ExtraWarnings, Options) ->
%% Some mistakes such as "{X} =:= {}" are found by strong
%% validation as well as by qlc. Prefer the warnings from qlc:
- Warnings1 = mforms(Warnings0) --
- ([{File,[{L,v3_core,nomatch}]} ||
- {File,[{L,qlc,M}]} <- mforms(ExtraWarnings),
- lists:member(M, [nomatch_pattern,nomatch_filter])]
- ++
- [{File,[{L,sys_core_fold,nomatch_guard}]} ||
- {File,[{L,qlc,M}]} <- mforms(ExtraWarnings),
- M =:= nomatch_filter]),
+ EWs = mforms(ExtraWarnings),
+ NoMatchLines =
+ [{File,get_line(Loc)} ||
+ {File,[{Loc,qlc,M}]} <- EWs,
+ lists:member(M, [nomatch_pattern,nomatch_filter])],
+ NoMatchGuardLines =
+ [{File,get_line(Loc)} ||
+ {File,[{Loc,qlc,nomatch_filter}]} <- EWs],
+ Warnings1 = filter_dupes(Warnings0, NoMatchLines, NoMatchGuardLines),
Warnings = Warnings1 ++ ExtraWarnings,
{Es1,Ws1} = compile_forms(Forms, Options),
Es = mforms(Errors) -- mforms(Es1),
@@ -195,6 +196,20 @@ mforms2(Tag, L) ->
end, lists:sort(L)),
lists:flatten(lists:sort(ML)).
+filter_dupes(Ws, NoMatchLines, NoMatchGuardLines) ->
+ lists:filter(
+ fun ({File,[{Loc,v3_core,nomatch}]}) ->
+ not lists:member({File,get_line(Loc)}, NoMatchLines);
+ ({File,[{Loc,sys_core_fold,nomatch_guard}]}) ->
+ not lists:member({File,get_line(Loc)}, NoMatchGuardLines);
+ (_) ->
+ true
+ end, Ws).
+
+get_line(Loc) ->
+ {line,Line} = erl_scan:attributes_info(Loc, line),
+ Line.
+
is_qlc_q_imported(Forms) ->
[[] || {attribute,_,import,{?APIMOD,FAs}} <- Forms, {?Q,1} <- FAs] =/= [].

0 comments on commit 22027c4

Please sign in to comment.