[erlang-questions] [Q] dialyzer message: The pattern X can never match the type Y

Per Gustafsson per.gustafsson@REDACTED
Wed May 28 21:42:12 CEST 2008


Ladislav Lenart wrote:
> Hello,
>
> first I'd like to say that dialyzer is a wonderful and
> easy-to-use tool. It has already found several bugs for
> me :-)
>
> But I don't understand what dialyzer is trying to tell
> me with a warning like:
>
>    The pattern X can never match the type Y.
>
> The actual code seems fine to me. It is similar to:
>
> %%%%%%%%%%%%%%%%
> -module(mod).
>
> -export(f/1).
>
> f(Arg) when Arg == foo; Arg == bar; Arg == baz ->
>      case Arg of
>          foo -> x();
>          _ -> y()
>      end.
> %%%%%%%%%%%%%%%%
>
> However, dialyzer does not report a warning like:
>
>    The pattern 'foo' can never match the type 'baz'
>
> for the module above.
>
> So I'd like to know what does the warning mean.
>
> Thanks in advance,
>
> Ladislav Lenart
>
>   

The most likely reason you get a warning like that, which is hard to 
understand is that you have something like this:

-module(mod).

-export([g/0]).

g() ->
  f(bar),...,f(baz).

f(Arg) when Arg == foo; Arg == bar; Arg == baz ->
     case Arg of
         foo -> x();
         _ -> y()
     end.

That is you never actually call f/1 with foo and f/1 is not exported.

Per
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>   




More information about the erlang-questions mailing list