Another bug in Erlang code

Kostis Sagonas <>
Fri Mar 18 09:58:49 CET 2005


  Another QUIZ inspired by bugs identified by the new type inference.


Who can spot the error in the following xmerl/src/xmerl.erl code?

============================================================================
%% @doc Exports simple XML content directly, without further context.

export_simple_content(Data, Callback) when atom(Callback) ->
    export_content(xmerl_lib:expand_content(Data),
                   callbacks(Callback));
export_simple_content(Data, Callbacks) when list(Callbacks) ->
    export_content(xmerl_lib:expand_element(Data), Callbacks).

%% @spec export_content(Content, Callbacks) -> term()
%%      Content = [Element]
%%      Callback = [atom()]
%% @doc Exports normal XML content directly, without further context.
export_content([#xmlText{value = Text} | Es], CBs) ->
    [apply_text_cb(CBs, Text) | export_content(Es, CBs)];
export_content([#xmlPI{} | Es], CBs) ->
    export_content(Es, CBs);
export_content([#xmlComment{} | Es], CBs) ->
    export_content(Es, CBs);
export_content([#xmlDecl{} | Es], CBs) ->
    export_content(Es, CBs);
export_content([E | Es], CBs) ->
    [export_element(E, CBs) | export_content(Es, CBs)];
export_content([], _CBs) ->
    [].
============================================================================

Hint: Just use your common sense from the information in function names.

Cheers,
Kostis

PS. The maintainer of xmerl might want to get in touch with me.
    I have a decently-sized list of discrepancies.




More information about the erlang-questions mailing list