[erlang-questions] mfa/0 built-in type and behaviour in R15/R16

Roberto Aloi prof3ta@REDACTED
Thu Mar 6 10:15:55 CET 2014


Hi,

Whilst R15B03 prevents you from redefine the mfa() built-in type:

R15$ erlc recon_trace.erl
recon_trace.erl:182: type mfa() is a builtin type; it cannot be redefined

R16 doesn't complain at all and allows the type to be redefined.

Is this intentional? I looked at erl_lint in both Erlang versions and, even
if mfa/0 seems to be defined as a default type in both cases, the type_def
function behaves very differently in the two Erlang versions. Looking at
the dict:is_key/2 function called as part of the top-level case in the
type_def function you get:

R15B03:

$ erlc recon_trace.erl
(<0.25.0>) call dict:is_key({mfa,0},{dict,67,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[[{boolean,0}|-1],
         [{'fun',0}|-1],
         [{function,0}|-1],
         [{no_return,0}|-1],
         [{shellfun,0},{line,{"recon_trace.erl",165}}],
         [{fn,0},{line,{"recon_trace.erl",180}}]],
        [],
        [[{'fun',2}|-1]],
        [[{iodata,0}|-1],[{mfa,0}|-1]],
        [[{char,0}|-1],
         [{identifier,0}|-1],
         [{integer,0}|-1],
         [{neg_integer,0}|-1],
         [{non_neg_integer,0}|-1],
         [{number,0}|-1],
         [{pos_integer,0}|-1]],
        [[{matchspec,0},{line,{"recon_trace.erl",164}}],
         [{millisecs,0},{line,{"recon_trace.erl",166}}],
         [{pidspec,0},{line,{"recon_trace.erl",167}}],
         [{max_traces,0},{line,{"recon_trace.erl",168}}],
         [{options,0},{line,{"recon_trace.erl",172}}],
         [{args,0},{line,{"recon_trace.erl",181}}],
         [{num_matches,0},{line,{"recon_trace.erl",183}}]],
        [[{dict,0}|-1],
         [{float,0}|-1],
         [{gb_set,0}|-1],
         [{iolist,0}|-1],
         [{list,0}|-1],
         [{maybe_improper_list,0}|-1],
         [{nonempty_list,0}|-1],
         [{nonempty_maybe_improper_list,0}|-1],
         [{pid,0}|-1],
         [{port,0}|-1],
         [{set,0}|-1],
         [{timeout,0}|-1],
         [{mod,0},{line,{"recon_trace.erl",179}}]],
        [[{byte,0}|-1],
         [{gb_tree,0}|-1],
         [{module,0}|-1],
         [{node,0}|-1],
         [{none,0}|-1],
         [{queue,0}|-1],
         [{reference,0}|-1],
         [{max_rate,0},{line,{"recon_trace.erl",169}}]],
        [[{atom,1}|-1],
         [{maybe_improper_list,2}|-1],
         [{nonempty_improper_list,2}|-1],
         [{nonempty_maybe_improper_list,2}|-1]],
        [[{bitstring,0}|-1],
         [{nonempty_string,0}|-1],
         [{range,2}|-1],
         [{string,0}|-1]],
        [[{digraph,0}|-1],[{max,0},{line,{"recon_trace.erl",182}}]],
        [[{any,0}|-1],[{arity,0}|-1],[{array,0}|-1],[{binary,0}|-1]],
        [],
        [[{binary,2}|-1],[{integer,1}|-1],[{var,1}|-1]],
        [[{bool,0}|-1],[{nil,0}|-1]],

[[{atom,0}|-1],[{list,1}|-1],[{nonempty_list,1}|-1],[{term,0}|-1]]}}})
(<0.25.0>) returned from dict:is_key/2 -> true

Indeed, in this case mfa/0 is part of the State and cannot be redefined, so
the right branch of the case is executed.

R16B03:

$ erlc recon_trace.erl
(<0.25.0>) call dict:is_key({mfa,0},{dict,12,16,16,8,80,48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[[{shellfun,0}|{typeinfo,type,[{line,{"recon_trace.erl",165}}]}],
         [{fn,0}|{typeinfo,type,[{line,{"recon_trace.erl",180}}]}]],
        [],[],[],[],
        [[{matchspec,0}|{typeinfo,type,[{line,{"recon_trace.erl",164}}]}],
         [{millisecs,0}|{typeinfo,type,[{line,{"recon_trace.erl",166}}]}],
         [{pidspec,0}|{typeinfo,type,[{line,{"recon_trace.erl",167}}]}],
         [{max_traces,0}|{typeinfo,type,[{line,{"recon_trace.erl",168}}]}],
         [{options,0}|{typeinfo,type,[{line,{"recon_trace.erl",172}}]}],
         [{args,0}|{typeinfo,type,[{line,{"recon_trace.erl",181}}]}],

 [{num_matches,0}|{typeinfo,type,[{line,{"recon_trace.erl",183}}]}]],
        [[{mod,0}|{typeinfo,type,[{line,{"recon_trace.erl",179}}]}]],
        [[{max_rate,0}|{typeinfo,type,[{line,{"recon_trace.erl",169}}]}]],
        [],[],
        [[{max,0}|{typeinfo,type,[{line,{"recon_trace.erl",182}}]}]],
        [],[],[],[],[]}}})
(<0.25.0>) returned from dict:is_key/2 -> false

It looks to me like the default types are not part of the state yet?

I need some coffee now.

-- 
Roberto Aloi
---
Website: http://roberto-aloi.com
Twitter: @robertoaloi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140306/c25b1ffe/attachment.htm>


More information about the erlang-questions mailing list