[erlang-questions] 12B4 dialyzer problem 6 - strings

Tobias Lindahl <>
Mon Sep 22 14:04:11 CEST 2008


Anthony Shipman wrote:
> I've got some code that accesses a driver and it looks like this:
> 
> 119: -spec parseDate(string()) -> integer() | badarg.
> 
> parseDate(Date) when is_list(Date) ->
>     Port = open(),
>     N = parseDate(Port, Date),
>     ok = close(Port),
>     N.
> 
> -spec parseDate(port(), string()) -> integer() | badarg.
> 
> parseDate(Port, Date) when is_port(Port), is_list(Date) ->
>     Bin = port_control(Port, ?CMD_PDATE, Date),
>     binary_to_term(Bin).
> 
> Dialyzer says, with -Wunderspecs, 
> 
> dwcAuxDrv.erl:119: Type specification dwcAuxDrv:parseDate/1 :: (string())
> -> integer() | 'badarg' is a supertype of the success typing: ([byte()])
> -> 'badarg' | integer()
> 
> I thought that string() and [byte()] would be the same. But delving into the 
> source code I find that a string() is a [char()] and a char() is an integer 
> in the range 0..16#10ffff (from hipe erl_types.erl). So there's a 
> contradiction in there. 

I'm not sure that it is contradicting, but yes it might be a bit 
surprising. Richard Carlsson set this limit when he implemented the 
original type domain, and I have just left it as is. Basically it is a 
trade-off to allow people to call their lists of integers strings even 
if they do not follow the [byte()] limit.

In general, the warnings that you get when using -Wunderspecs (and 
friends) is something you might want to look at, but not necessarily fix.

Tobias



More information about the erlang-questions mailing list