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

Tobias Lindahl <>
Thu May 29 10:58:39 CEST 2008


Per is correct in his explanation, but I just wanted to clarify further 
that the warnings from Dialyzer is correct.

In your code you have only one call to the non-exported function 
create_files/2 where the second argument is tagged with 'yrl'

  create_files(Path, {yrl, "f", rebuilt_mod_time}),

Since the function is not exported, the information gets forwarded from 
the call site. In the function clause where this is matched, you then 
check the third position of the tuple in the second argument.

create_files(Path, {yrl, Prefix, Type}) when Type == up_to_date; Type == 
rebuilt_no_exist; Type == rebuilt_mod_time ->
  case Type of
     up_to_date ->
  case Type of
     rebuilt_no_exist ->
  case Type of
     up_to_date ->

The case clauses cannot match because the atom is always 
'rebuilt_mod_time' because of the call forwarding, and Dialyzer emits 
warnings about this.

Ladislav Lenart wrote:
> Ok, this should be it, except that I think the code is actually
> executed. Thanks to your explanation, I finally managed to create
> a module that reports the warning. It is based on the real module.

I hope it is now clear that the code in the case clauses never executes. 
In fact, we strive to have sound (i.e., never false) warnings from 
Dialyzer, so we are very interested in getting reports where the 
warnings are suspicious, either to clarify them or to fix the bugs that 
cause them.

Best regards,

> Thank you both for your helpful explanations; I am already looking
> forward to more enlightenment to come :-)
> Ladislav Lenart
> ------------------------------------------------------------------------
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list