From ba24a5d2f839bb0cfef00bdb8bf74744e77ed587 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 17 Mar 2010 09:11:23 +0000 Subject: OTP-8522 Avoid duplicated 'undefined' in record field types The Erlang parser no longer duplicates the singleton type undefined in the type of record fields without initial value. --- lib/stdlib/src/erl_parse.yrl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/src/erl_parse.yrl') diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 435464227f..ea91ec5927 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -734,13 +734,29 @@ record_fields([{typed,Expr,TypeInfo}|Fields]) -> case Expr of {match, _, _, _} -> TypeInfo; %% If we have an initializer. {atom, La, _} -> - lift_unions(abstract(undefined, La), TypeInfo) + case has_undefined(TypeInfo) of + false -> + lift_unions(abstract(undefined, La), TypeInfo); + true -> + TypeInfo + end end, [{typed_record_field,Field,TypeInfo1}|record_fields(Fields)]; record_fields([Other|_Fields]) -> ret_err(?line(Other), "bad record field"); record_fields([]) -> []. +has_undefined({atom,_,undefined}) -> + true; +has_undefined({ann_type,_,[_,T]}) -> + has_undefined(T); +has_undefined({paren_type,_,[T]}) -> + has_undefined(T); +has_undefined({type,_,union,Ts}) -> + lists:any(fun has_undefined/1, Ts); +has_undefined(_) -> + false. + term(Expr) -> try normalise(Expr) catch _:_R -> ret_err(?line(Expr), "bad attribute") -- cgit v1.2.3