From 21214178d05ffa482d7377a22285b38834566d2c Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Mon, 1 Jan 2018 17:48:09 +0000 Subject: Fix false Dialyzer warnings for erl_tar:table/1 'tar_entry()' values are only returned if we specify the 'verbose' option when calling table/2, which table/1 doesn't do. Now, it appears that Dialyzer as of OTP 20 is clever enough to realize that the return type of table/1 must intersect with the return type of table/2, and so it ignores the fact that table/1 says it returns strings, and therefore its callers are expected to be dealing with 'tar_entry()' tuples, and never with strings. This is obviously a mismatch between what the code does and what the spec says is does, leading to false Dialyzer warnings on code that uses table/1 (and, presumably, also table/2 when called without the 'verbose' option.) --- lib/stdlib/src/erl_tar.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stdlib/src/erl_tar.erl b/lib/stdlib/src/erl_tar.erl index 76f0b38108..5ee584d612 100644 --- a/lib/stdlib/src/erl_tar.erl +++ b/lib/stdlib/src/erl_tar.erl @@ -189,7 +189,7 @@ table(Name) -> %% Returns a list of names of the files in the tar file Name. %% Options accepted: compressed, verbose, cooked. -spec table(open_handle(), [compressed | verbose | cooked]) -> - {ok, [tar_entry()]} | {error, term()}. + {ok, [string() | tar_entry()]} | {error, term()}. table(Name, Opts) when is_list(Opts) -> foldl_read(Name, fun table1/4, [], table_opts(Opts)). -- cgit v1.2.3 From 50c99a1a07feed6f160a700c5f39becc10f04802 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 9 Jan 2018 15:03:36 +0100 Subject: dialyzer: Add a test of erl_tar:table/1,2 --- lib/dialyzer/test/small_SUITE_data/src/erl_tar_table.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/dialyzer/test/small_SUITE_data/src/erl_tar_table.erl diff --git a/lib/dialyzer/test/small_SUITE_data/src/erl_tar_table.erl b/lib/dialyzer/test/small_SUITE_data/src/erl_tar_table.erl new file mode 100644 index 0000000000..2dc00d272a --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/erl_tar_table.erl @@ -0,0 +1,14 @@ +-module(erl_tar_table). + +%% OTP-14860, PR 1670. + +-export([t/0, v/0, x/0]). + +t() -> + {ok, ["file"]} = erl_tar:table("table.tar"). + +v() -> + {ok, [{_,_,_,_,_,_,_}]} = erl_tar:table("table.tar", [verbose]). + +x() -> + {ok, ["file"]} = erl_tar:table("table.tar", []). -- cgit v1.2.3