mirror of
https://github.com/valitydev/parse_trans.git
synced 2024-11-06 08:35:17 +00:00
Merge pull request #7 from legoscia/is_record_overlapping_contracts
Fix "overlapping domain" Dialyzer warning for '#is_record-'/{1,2}
This commit is contained in:
commit
fb08d7eedf
@ -136,9 +136,8 @@
|
|||||||
%% '#pos-'(s, Attr) ->
|
%% '#pos-'(s, Attr) ->
|
||||||
%% '#pos-s'(Attr).
|
%% '#pos-s'(Attr).
|
||||||
%%
|
%%
|
||||||
%% -spec '#is_record-'(#r{}) -> true;
|
%% -spec '#is_record-'(any()) -> boolean().
|
||||||
%% (#s{}) -> true;
|
%%
|
||||||
%% (any()) -> false.
|
|
||||||
%% '#is_record-'(X) ->
|
%% '#is_record-'(X) ->
|
||||||
%% if
|
%% if
|
||||||
%% is_record(X, r) ->
|
%% is_record(X, r) ->
|
||||||
@ -149,9 +148,8 @@
|
|||||||
%% false
|
%% false
|
||||||
%% end.
|
%% end.
|
||||||
%%
|
%%
|
||||||
%% -spec '#is_record-'(r, #r{}) -> true;
|
%% -spec '#is_record-'(any(), any()) -> boolean().
|
||||||
%% (s, #s{}) -> true;
|
%%
|
||||||
%% (any(), any()) -> false.
|
|
||||||
%% '#is_record-'(s, Rec) when tuple_size(Rec) == 2, element(1, Rec) == s ->
|
%% '#is_record-'(s, Rec) when tuple_size(Rec) == 2, element(1, Rec) == s ->
|
||||||
%% true;
|
%% true;
|
||||||
%% '#is_record-'(r, Rec) when tuple_size(Rec) == 4, element(1, Rec) == r ->
|
%% '#is_record-'(r, Rec) when tuple_size(Rec) == 4, element(1, Rec) == r ->
|
||||||
@ -756,6 +754,7 @@ t_atom(L, A) -> {atom, L, A}.
|
|||||||
t_integer(L) -> {type, L, integer, []}.
|
t_integer(L) -> {type, L, integer, []}.
|
||||||
t_integer(L, I) -> {integer, L, I}.
|
t_integer(L, I) -> {integer, L, I}.
|
||||||
t_list(L, Es) -> {type, L, list, Es}.
|
t_list(L, Es) -> {type, L, list, Es}.
|
||||||
|
t_boolean(L) -> {type, L, boolean, []}.
|
||||||
%% t_tuple(L, Es) -> {type, L, tuple, Es}.
|
%% t_tuple(L, Es) -> {type, L, tuple, Es}.
|
||||||
t_record(L, A) -> {type, L, record, [{atom, L, A}]}.
|
t_record(L, A) -> {type, L, record, [{atom, L, A}]}.
|
||||||
|
|
||||||
@ -929,10 +928,14 @@ f_info(Acc, L) ->
|
|||||||
f_isrec_2(#pass1{records = Rs, exports = Es} = Acc, L) ->
|
f_isrec_2(#pass1{records = Rs, exports = Es} = Acc, L) ->
|
||||||
Fname = list_to_atom(fname_prefix(is_record, Acc)),
|
Fname = list_to_atom(fname_prefix(is_record, Acc)),
|
||||||
Info = [{R,length(As) + 1} || {R,As} <- Rs, lists:member(R, Es)],
|
Info = [{R,length(As) + 1} || {R,As} <- Rs, lists:member(R, Es)],
|
||||||
[funspec(L, Fname,
|
[%% This contract is correct, but is ignored by Dialyzer because it
|
||||||
[{[t_atom(L, R), t_record(L, R)], t_atom(L, true)}
|
%% has overlapping domains:
|
||||||
|| R <- Es] ++
|
%% funspec(L, Fname,
|
||||||
[{[t_any(L), t_any(L)], t_atom(L, false)}]),
|
%% [{[t_atom(L, R), t_record(L, R)], t_atom(L, true)}
|
||||||
|
%% || R <- Es] ++
|
||||||
|
%% [{[t_any(L), t_any(L)], t_atom(L, false)}]),
|
||||||
|
%% This is less specific, but more useful to Dialyzer:
|
||||||
|
funspec(L, Fname, [{[t_any(L), t_any(L)], t_boolean(L)}]),
|
||||||
{function, L, Fname, 2,
|
{function, L, Fname, 2,
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({R, Ln}) ->
|
fun({R, Ln}) ->
|
||||||
@ -1007,10 +1010,14 @@ f_pos_2(#pass1{exports = Es} = Acc, L) ->
|
|||||||
|
|
||||||
f_isrec_1(Acc, L) ->
|
f_isrec_1(Acc, L) ->
|
||||||
Fname = list_to_atom(fname_prefix(is_record, Acc)),
|
Fname = list_to_atom(fname_prefix(is_record, Acc)),
|
||||||
[funspec(L, Fname,
|
[%% This contract is correct, but is ignored by Dialyzer because it
|
||||||
[{[t_record(L, R)], t_atom(L, true)}
|
%% has overlapping domains:
|
||||||
|| R <- Acc#pass1.exports]
|
%% funspec(L, Fname,
|
||||||
++ [{[t_any(L)], t_atom(L, false)}]),
|
%% [{[t_record(L, R)], t_atom(L, true)}
|
||||||
|
%% || R <- Acc#pass1.exports]
|
||||||
|
%% ++ [{[t_any(L)], t_atom(L, false)}]),
|
||||||
|
%% This is less specific, but more useful to Dialyzer:
|
||||||
|
funspec(L, Fname, [{[t_any(L)], t_boolean(L)}]),
|
||||||
{function, L, Fname, 1,
|
{function, L, Fname, 1,
|
||||||
[{clause, L,
|
[{clause, L,
|
||||||
[{var, L, 'X'}],
|
[{var, L, 'X'}],
|
||||||
|
Loading…
Reference in New Issue
Block a user