From 9c132d619bb3b88201019a39d064f2852a067fb0 Mon Sep 17 00:00:00 2001 From: Tomas Abrahamsson Date: Thu, 15 Sep 2011 19:38:23 +0200 Subject: Quote atoms if necessary in types Atoms in some occurrences were not correctly quoted when formatted to strings, for instance by the typer program. Example: -module(tb). -export(['UPPERCASE-FUNCTION-NAME'/0, f1/0, f2/0, f3/0]). -record('UPPERCASE-RECORD-NAME', {x}). -record(r2, {'UPPERCASE-FIELD-NAME'}). -type 'UPPERCASE-TYPE-NAME'() :: integer(). 'UPPERCASE-FUNCTION-NAME'() -> ok. f1() -> #'UPPERCASE-RECORD-NAME'{x=1}. f2() -> #r2{'UPPERCASE-FIELD-NAME'=1}. -spec f3() -> 'UPPERCASE-TYPE-NAME'(). f3() -> 1. Given the program above, the output from typer --plt some.plt tb.erl resulted in the following specs being printed: -spec UPPERCASE-FUNCTION-NAME() -> 'ok'. -spec f1() -> #UPPERCASE-RECORD-NAME{x::1}. -spec f2() -> #r2{UPPERCASE-FIELD-NAME::1}. -spec f3() -> UPPERCASE-TYPE-NAME(). This commit changes the output to become the following: -spec 'UPPERCASE-FUNCTION-NAME'() -> 'ok'. -spec f1() -> #'UPPERCASE-RECORD-NAME'{x::1}. -spec f2() -> #r2{'UPPERCASE-FIELD-NAME'::1}. -spec f3() -> 'UPPERCASE-TYPE-NAME'(). --- lib/hipe/cerl/erl_types.erl | 16 +++++++++++----- lib/typer/src/typer.erl | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl index 1748c1cc16..7ff170776e 100644 --- a/lib/hipe/cerl/erl_types.erl +++ b/lib/hipe/cerl/erl_types.erl @@ -211,7 +211,8 @@ record_field_diffs_to_string/2, subst_all_vars_to_any/1, lift_list_to_pos_empty/1, - is_erl_type/1 + is_erl_type/1, + atom_to_string/1 ]). %%-define(DO_ERL_TYPES_TEST, true). @@ -3360,14 +3361,14 @@ t_to_string(?var(Id), _RecDict) when is_integer(Id) -> record_to_string(Tag, [_|Fields], FieldNames, RecDict) -> FieldStrings = record_fields_to_string(Fields, FieldNames, RecDict, []), - "#" ++ atom_to_list(Tag) ++ "{" ++ string:join(FieldStrings, ",") ++ "}". + "#" ++ atom_to_string(Tag) ++ "{" ++ string:join(FieldStrings, ",") ++ "}". record_fields_to_string([F|Fs], [{FName, _DefType}|FDefs], RecDict, Acc) -> NewAcc = case t_is_any(F) orelse t_is_atom('undefined', F) of true -> Acc; false -> - StrFV = atom_to_list(FName) ++ "::" ++ t_to_string(F, RecDict), + StrFV = atom_to_string(FName) ++ "::" ++ t_to_string(F, RecDict), %% ActualDefType = t_subtract(DefType, t_atom('undefined')), %% Str = case t_is_any(ActualDefType) of %% true -> StrFV; @@ -3393,7 +3394,7 @@ field_diffs([F|Fs], [{FName, DefType}|FDefs], RecDict, Acc) -> case t_is_subtype(F, DefType) of true -> Acc; false -> - Str = atom_to_list(FName) ++ "::" ++ t_to_string(DefType, RecDict), + Str = atom_to_string(FName) ++ "::" ++ t_to_string(DefType, RecDict), [Str|Acc] end, field_diffs(Fs, FDefs, RecDict, NewAcc); @@ -3906,7 +3907,7 @@ t_form_to_string({type, _L, union, Args}) -> string:join(t_form_to_string_list(Args), " | "); t_form_to_string({type, _L, Name, []} = T) -> try t_to_string(t_from_form(T)) - catch throw:{error, _} -> atom_to_list(Name) ++ "()" + catch throw:{error, _} -> atom_to_string(Name) ++ "()" end; t_form_to_string({type, _L, Name, List}) -> io_lib:format("~w(~s)", @@ -3920,6 +3921,11 @@ t_form_to_string_list([H|T], Acc) -> t_form_to_string_list([], Acc) -> lists:reverse(Acc). +-spec atom_to_string(atom()) -> string(). + +atom_to_string(Atom) -> + lists:flatten(io_lib:format("~w", [Atom])). + %%============================================================================= %% %% Utilities diff --git a/lib/typer/src/typer.erl b/lib/typer/src/typer.erl index e40c4f39cd..fd906c8c46 100644 --- a/lib/typer/src/typer.erl +++ b/lib/typer/src/typer.erl @@ -539,7 +539,7 @@ get_type_string(F, A, Info, Mode) -> case {Mode, Type} of {file, {contract, _}} -> ""; _ -> - Prefix = lists:concat(["-spec ", F]), + Prefix = lists:concat(["-spec ", erl_types:atom_to_string(F)]), lists:concat([Prefix, TypeStr, "."]) end; true -> -- cgit v1.2.3 From 291e32daaaa7f485d67f1ee1e29b802152f9ae42 Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Mon, 19 Sep 2011 17:30:03 +0300 Subject: Update Dialyzer's reference results --- lib/dialyzer/test/r9c_SUITE_data/results/asn1 | 6 +++--- lib/dialyzer/test/small_SUITE_data/results/my_sofs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/dialyzer/test/r9c_SUITE_data/results/asn1 b/lib/dialyzer/test/r9c_SUITE_data/results/asn1 index 571e562d0d..292275dd6e 100644 --- a/lib/dialyzer/test/r9c_SUITE_data/results/asn1 +++ b/lib/dialyzer/test/r9c_SUITE_data/results/asn1 @@ -6,7 +6,7 @@ asn1ct.erl:672: The pattern <{'false', Result}, _, _> can never match the type < asn1ct.erl:909: Guard test is_atom(Ext::[49 | 97 | 98 | 100 | 110 | 115]) can never succeed asn1ct_check.erl:1698: The pattern {'error', _} can never match the type [any()] asn1ct_check.erl:2733: The pattern {'type', Tag, _, _, _, _} can never match the type 'ASN1_OPEN_TYPE' | {_,_} | {'fixedtypevaluefield',_,_} -asn1ct_check.erl:2738: The pattern <_S, _> can never match since previous clauses completely covered the type <#state{},#ObjectClassFieldType{class::#objectclass{fields::maybe_improper_list() | {_,_,_,_}},fieldname::{_,maybe_improper_list()},type::'ASN1_OPEN_TYPE' | {_,_} | {'fixedtypevaluefield',_,_}}> +asn1ct_check.erl:2738: The pattern <_S, _> can never match since previous clauses completely covered the type <#state{},#'ObjectClassFieldType'{class::#objectclass{fields::maybe_improper_list() | {_,_,_,_}},fieldname::{_,maybe_improper_list()},type::'ASN1_OPEN_TYPE' | {_,_} | {'fixedtypevaluefield',_,_}}> asn1ct_check.erl:2887: The variable Other can never match since previous clauses completely covered the type any() asn1ct_check.erl:3188: The pattern <_S, [], B> can never match the type <#state{},{'SingleValue',_},{'ValueRange',_}> asn1ct_check.erl:3190: The pattern <_S, A, []> can never match the type <#state{},{'SingleValue',_},{'ValueRange',_}> @@ -29,8 +29,8 @@ asn1ct_check.erl:5128: Guard test is_record(Type::{_,_} | {'fixedtypevaluefield' asn1ct_check.erl:540: The pattern <_S, {'poc', _ObjSet, _Params}> can never match since previous clauses completely covered the type <#state{},_> asn1ct_check.erl:5517: The pattern <_, []> can never match the type <_,[{'ABSTRACT-SYNTAX',{_,_,_}} | {'TYPE-IDENTIFIER',{_,_,_}},...]> asn1ct_constructed_ber.erl:1075: The pattern {{{'ObjectClassFieldType', _, _, _, {'objectfield', PrimFieldName1, PFNList}}, _}, {'componentrelation', _, _}} can never match the type {#type{},_} -asn1ct_constructed_ber.erl:695: The pattern {'EXTENSIONMARK', _, _} can never match the type #ComponentType{} -asn1ct_constructed_ber.erl:748: The pattern can never match the type <_,maybe_improper_list(),[#ComponentType{typespec::{_,_,_,_,_,_}}]> +asn1ct_constructed_ber.erl:695: The pattern {'EXTENSIONMARK', _, _} can never match the type #'ComponentType'{} +asn1ct_constructed_ber.erl:748: The pattern can never match the type <_,maybe_improper_list(),[#'ComponentType'{typespec::{_,_,_,_,_,_}}]> asn1ct_constructed_ber_bin_v2.erl:914: The pattern {{{'ObjectClassFieldType', _, _, _, {'objectfield', PrimFieldName1, PFNList}}, _}, {'componentrelation', _, _}} can never match the type {#type{},_} asn1ct_gen.erl:740: The pattern [] can never match the type [any(),...] asn1ct_gen_ber.erl:974: The pattern can never match the type <_,[#typedef{name::atom(),typespec::{_,_,_,_,_,_}}]> diff --git a/lib/dialyzer/test/small_SUITE_data/results/my_sofs b/lib/dialyzer/test/small_SUITE_data/results/my_sofs index bfee0bce0d..bc97c08d62 100644 --- a/lib/dialyzer/test/small_SUITE_data/results/my_sofs +++ b/lib/dialyzer/test/small_SUITE_data/results/my_sofs @@ -1,3 +1,3 @@ -my_sofs.erl:34: The pattern {'Set', _, _} can never match the type #OrdSet{} -my_sofs.erl:54: The pattern {'Set', _, _} can never match the type #OrdSet{} +my_sofs.erl:34: The pattern {'Set', _, _} can never match the type #'OrdSet'{} +my_sofs.erl:54: The pattern {'Set', _, _} can never match the type #'OrdSet'{} -- cgit v1.2.3