I recently started using Dialyzer in my project and have been going through and fixing all the warnings. I’m down to one!
I call the :zip.create/3
function like this:
:zip.create("ceu_files.zip", [{'file1', "content1"}, {'file2',"content2"}], [:memory])
Dialyzer issues a warning saying that the function call will not succeed. However, the function has been working for months now. Is it trying to tell me that there’s an code path that results in the function not working?
The difference between the success typing and the contract is confusing and it’s hard for me to understand what it’s trying to convey. I’m guessing it has something to do with the file name (first argument), but I’m not entirely sure.
Do you have an idea of what this error message is trying to communicate?
The function call will not succeed.
:zip.create(_zip_name :: <<_::8, _::size(1)>>, _files :: [any()], [:memory])
will never return since the success typing is:
(
atom() | [atom() | [any()] | char()],
[
atom()
| [atom() | [any()] | char()]
| {atom() | [atom() | [any()] | char()], binary()}
| {atom() | [atom() | [any()] | char()], binary(),
{:file_info, :undefined | non_neg_integer(),
:device | :directory | :other | :regular | :symlink | :undefined,
:none | :read | :read_write | :undefined | :write,
:undefined | non_neg_integer() | {_, _}, :undefined | non_neg_integer() | {_, _},
:undefined | non_neg_integer() | {_, _}, :undefined | non_neg_integer(),
:undefined | non_neg_integer(), :undefined | non_neg_integer(),
:undefined | non_neg_integer(), :undefined | non_neg_integer(),
:undefined | non_neg_integer(), :undefined | non_neg_integer()}}
],
[
:cooked
| :memory
| :verbose
| {:comment, string()}
| {:compress, :all | [[any()]] | {:add, [any()]} | {:del, [any()]}}
| {:cwd, string()}
| {:uncompress, :all | [[any()]] | {:add, [any()]} | {:del, [any()]}}
]
) ::
{:error, _}
| {:ok,
atom() | [atom() | [any()] | char()] | {atom() | [atom() | [any()] | char()], binary()}}
and the contract is
(name, fileList, options) :: retValue
when name: :file.name(),
fileList: [:FileSpec],
fileSpec:
:file.name() | {:file.name(), binary()} | {:file.name(), binary(), :file.file_info()},
options: [:Option],
option: create_option(),
retValue:
{:ok, FileName :: filename()}
| {:ok, {FileName :: filename(), binary()}}
| {:error, Reason :: term()}