|
|
| Author |
Message |
< Erlang bugs mailing list ~ lists:concat/1 spec inconsistent with implementation or bug |
| Guest |
Posted: Wed Jul 28, 2010 8:07 am |
|
|
|
Guest
|
On 07/21/2010 07:10 PM, Rickard Olsson wrote:
> Hi,
>
> When running Dialyzer on the code below I get the following messages: "The
> call lists:concat([['a,...],...]) breaks the contract ([concat_thing()]) ->
> string()" and "Function unused_function/1 will never be called"
>
> Test code:
>
> -export([parse/0]).
>
> parse()->
> concat(),
> unused_function(a).
>
> concat() ->
> lists:concat([[a]]).
>
> unused_function(A) ->
> A.
>
> The line: "lists:concat([[a]])." runs fine in the shell, but seems to cause
> the dialyzer to stop, which I assume is the reason it warns that
> unused_function/1 will never be used, even though it is used. If the arity
> is changed to 0 and the arguments removed from the call, the warning seems
> to disapear though.
>
> Is it a bug in the lists:concat/1's spec or in Dialyzer?
>
> Running:
> openSUSE 11.0 (X86-64)
> Erlang R14A (erts-5. [source] [64-bit]
> Dialyzer v2.3.0
>
> Regards,
> Rickard Olsson
> Erlang Solutions
>
>
In my opinion, this is not a bug in the spec and certainly not in
Dialyzer. The
lists:concat spec is:
-type concat_thing() :: atom() | integer() | float() | string().
-spec concat([concat_thing()]) -> string().
The line: "lists:concat([[a]])." runs (i.e. does not crash) in the shell
because the term
[a] is assumed to be a string by the lists:concat function. However,
Dialyzer is able
to distinguish a string from a list of atoms and, since the spec
declares that this
function should only by used with [concat_thing()], emits a warning. In
addition,
the lists:concat function is supposed to return a list of characters
(i.e. a string). This
is not the case with the call "lists:concat([[a]])":
> lists:concat([[a]]).
[a]
So it does not crash because it can also handle lists because it has to
handle strings,
but it does not behave correctly when it is given lists that do not
contain characters.
________________________________________________________________
erlang-bugs (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-bugs-unsubscribe@erlang.org
Post received from mailinglist |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|