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

Anthony Shipman als@REDACTED
Sun Sep 21 18:43:13 CEST 2008


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. 

-- 
Anthony Shipman                    Mamas don't let your babies 
als@REDACTED                   grow up to be outsourced.



More information about the erlang-questions mailing list