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

Kostis Sagonas <>
Thu May 29 10:56:21 CEST 2008

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.

Well, this was it.  If you look at your test/0 function, the only call 
to create_files/2 where the second argument is the 'yrl' tuple is:

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

The clause:

create_files(Path, {yrl, Prefix, Type}) when Type == up_to_date; Type == 
rebuilt_no_exist; Type == rebuilt_mod_time ->
     [YrlName, ErlName] = [filename:join(Path, Prefix ++ Each) || Each 
<- [".yrl", ".erl"]],
     MakeName = filename:join(Path, "Xmakefile"),
     EmptyContent = "",
     MakeContent = "{yrl, \"*.yrl\", []}.",
     {Date, _Time} = erlang:localtime(),
     case Type of
	up_to_date ->		% ***
     create_file(YrlName, EmptyContent, {Date, SourceTime}),
     case Type of
	rebuilt_no_exist ->	% ***
     create_file(MakeName, MakeContent, leave),
     case Type of
	up_to_date ->		% ***

contains a lot of redundant code in the lines shown with ***

This code cannot possibly execute and therefore you get the warnings:

dialyzer_test.erl:77: The pattern 'up_to_date' can never match the type 
dialyzer_test.erl:86: The pattern 'rebuilt_no_exist' can never match the 
type 'rebuilt_mod_time'
dialyzer_test.erl:93: The pattern 'up_to_date' can never match the type 


More information about the erlang-questions mailing list