[erlang-questions] http_uri_parse/1 inconsistent return value + dialyser headache

Motiejus Jakštys <>
Tue Aug 14 12:46:28 CEST 2012


On Tue, Aug 14, 2012 at 1:32 PM, Zabrane Mickael <> wrote:
> Hi guys, Hi Kostis,
>
> http_uri_parse/1 returns inconsistent value since 15RB.
> I'm trying to build a wrapper around it to make my code works on =<R14B04 too.
>
> Here's what i got so far:
>
> -spec http_uri_parse([byte()]) -> {ok, tuple()} | {error, atom()}.
> http_uri_parse(URL) when is_list(URL) ->
>     case http_uri:parse(URL) of
>         {ok,{Scheme, UserInfo, Host, Port, Path, Query}} -> %% >=R15B
>             http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query);
>         {Scheme, UserInfo, Host, Port, Path, Query} -> %% =< R14B               <------- LINE 1106
>             http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query);
>         Error ->
>             Error
>     end.
>
> http_uri_parse_1(Scheme, UserInfo, Host, Port, Path, Query) ->
>     {ok, {Scheme, UserInfo, Host, Port, Path, Query}}.
>
> But Dilayzer isn't happy:
>
> Checking whether the PLT /Users/younes/.otp_plt is up-to-date... yes
>   Proceeding with analysis...
> pimco.erl:1106: The pattern {Scheme, UserInfo, Host, Port, Path, Query} can never match the type {'error','no_scheme' | {_,atom(),_}}
>
>
> Any hint/help to get rid of this warning?

One way would be to define a constant at compile-time which version of
Erlang are you running. Then check for it in source and put the right
function/case statement accordingly.

rebar -> erl_opts -> platform_define is one of the ways to define that constant.

-- 
Motiejus Jakštys



More information about the erlang-questions mailing list