From b4d94db355d69f80aeb39ca9efe80fb9e2f56c57 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 23 May 2011 17:10:01 +0300 Subject: Fix crash when a contract range warning is emitted for a module already in plt Warnings about wrong contract ranges are post-processed to be displayed in the file/line that contains the contract, although they can also be emitted while processing other modules. For this relocation to succeed the module that contains the contract should be currently under analysis. If this is not the case the warning is displayed in the file/line of the call that proves the discrepancy in the contract. --- lib/dialyzer/src/dialyzer_succ_typings.erl | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/dialyzer/src/dialyzer_succ_typings.erl b/lib/dialyzer/src/dialyzer_succ_typings.erl index b8da57d3f9..dc5a3fed37 100644 --- a/lib/dialyzer/src/dialyzer_succ_typings.erl +++ b/lib/dialyzer/src/dialyzer_succ_typings.erl @@ -158,20 +158,27 @@ postprocess_dataflow_warns([], _State, WAcc, Acc) -> postprocess_dataflow_warns([{?WARN_CONTRACT_RANGE, {CallF, CallL}, Msg}|Rest], #st{codeserver = Codeserver} = State, WAcc, Acc) -> {contract_range, [Contract, M, F, A, ArgStrings, CRet]} = Msg, - {ok, {{ContrF, _ContrL} = FileLine, _C}} = - dialyzer_codeserver:lookup_mfa_contract({M,F,A}, Codeserver), - case CallF =:= ContrF of - true -> + case dialyzer_codeserver:lookup_mfa_contract({M,F,A}, Codeserver) of + {ok, {{ContrF, _ContrL} = FileLine, _C}} -> + case CallF =:= ContrF of + true -> + NewMsg = {contract_range, [Contract, M, F, ArgStrings, CallL, CRet]}, + W = {?WARN_CONTRACT_RANGE, FileLine, NewMsg}, + Filter = + fun({?WARN_CONTRACT_TYPES, FL, _}) when FL =:= FileLine -> false; + (_) -> true + end, + FilterWAcc = lists:filter(Filter, WAcc), + postprocess_dataflow_warns(Rest, State, FilterWAcc, [W|Acc]); + false -> + postprocess_dataflow_warns(Rest, State, WAcc, Acc) + end; + error -> + %% The contract is not in a module that is currently under analysis. + %% We display the warning in the file/line of the call. NewMsg = {contract_range, [Contract, M, F, ArgStrings, CallL, CRet]}, - W = {?WARN_CONTRACT_RANGE, FileLine, NewMsg}, - Filter = - fun({?WARN_CONTRACT_TYPES, FL, _}) when FL =:= FileLine -> false; - (_) -> true - end, - FilterWAcc = lists:filter(Filter, WAcc), - postprocess_dataflow_warns(Rest, State, FilterWAcc, [W|Acc]); - false -> - postprocess_dataflow_warns(Rest, State, WAcc, Acc) + W = {?WARN_CONTRACT_RANGE, {CallF, CallL}, NewMsg}, + postprocess_dataflow_warns(Rest, State, WAcc, [W|Acc]) end; postprocess_dataflow_warns([W|Rest], State, Wacc, Acc) -> postprocess_dataflow_warns(Rest, State, Wacc, [W|Acc]). -- cgit v1.2.3