From 3c31bdb47066c33566405ee731d6cdafd206444e Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 3 Jun 2021 11:39:14 +0200 Subject: stdlib: Let the linter report all locations for undef types The Erlang code linter used to report the last location where an undefined type was used. Reporting all locations is similar to how undefined functions and undefined records are reported. --- lib/stdlib/test/erl_lint_SUITE.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/test/erl_lint_SUITE.erl') diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index cf43551692..f6888721db 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -3725,7 +3725,10 @@ predef(Config) when is_list(Config) -> %% dict(), digraph() and so on were removed in Erlang/OTP 18.0. E2 = get_compilation_result(Config, "predef2", []), Tag = undefined_type, - {[{{7,13},erl_lint,{Tag,{array,0}}}, + {[{{5,2},erl_lint,{Tag,{array,0}}}, + {{5,2},erl_lint,{Tag,{digraph,0}}}, + {{5,2},erl_lint,{Tag,{gb_set,0}}}, + {{7,13},erl_lint,{Tag,{array,0}}}, {{12,12},erl_lint,{Tag,{dict,0}}}, {{17,15},erl_lint,{Tag,{digraph,0}}}, {{27,14},erl_lint,{Tag,{gb_set,0}}}, -- cgit v1.2.1 From 59cc16df4cb0b171e09e38e7924b7d719af1f834 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Fri, 4 Jun 2021 09:22:59 +0200 Subject: stdlib: Let the linter check unused types properly See also https://github.com/erlang/otp/issues/4784. A type like `t() :: [t()]' can now be reported as unused. Types occurring in specs of unused functions or in unused records are considered used. This is consistent with how the warning for unused records is implemented. --- lib/stdlib/test/erl_lint_SUITE.erl | 62 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'lib/stdlib/test/erl_lint_SUITE.erl') diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index f6888721db..77337a7e05 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -74,7 +74,8 @@ warn_missing_spec/1, otp_16824/1, underscore_match/1, - unused_record/1]). + unused_record/1, + unused_type2/1]). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -98,7 +99,7 @@ all() -> stacktrace_syntax, otp_14285, otp_14378, external_funs, otp_15456, otp_15563, unused_type, binary_types, removed, otp_16516, inline_nifs, warn_missing_spec, otp_16824, - underscore_match, unused_record]. + underscore_match, unused_record, unused_type2]. groups() -> [{unused_vars_warn, [], @@ -4634,6 +4635,63 @@ unused_record(Config) when is_list(Config) -> ok. +unused_type2(Config) when is_list(Config) -> + Ts = [{unused_type2_1, + <<"-type t() :: [t()]. + t() -> + a. + ">>, + {[]}, + {warnings,[{{1,22},erl_lint,{unused_type,{t,0}}}, + {{2,15},erl_lint,{unused_function,{t,0}}}]}}, + {unused_type2_2, + <<"-type t1() :: t2(). + -type t2() :: t1(). + t() -> + a. + ">>, + {[]}, + {warnings,[{{1,22},erl_lint,{unused_type,{t1,0}}}, + {{2,16},erl_lint,{unused_type,{t2,0}}}, + {{3,16},erl_lint,{unused_function,{t,0}}}]}}, + {unused_type2_3, + <<"-callback cb() -> t(). + -type t() :: atom(). + t() -> + a. + ">>, + {[]}, + {warnings,[{{3,16},erl_lint,{unused_function,{t,0}}}]}}, + {unused_type2_4, + <<"-spec t() -> t(). + -type t() :: atom(). + t() -> + a. + ">>, + {[]}, + {warnings,[{{3,16},erl_lint,{unused_function,{t,0}}}]}}, + {unused_type2_5, + <<"-export_type([t/0]). + -type t() :: atom(). + t() -> + a. + ">>, + {[]}, + {warnings,[{{3,16},erl_lint,{unused_function,{t,0}}}]}}, + {unused_type2_6, + <<"-record(r, {f :: t()}). + -type t() :: atom(). + t() -> + a. + ">>, + {[]}, + {warnings,[{{1,22},erl_lint,{unused_record,r}}, + {{3,16},erl_lint,{unused_function,{t,0}}}]}} + ], + [] = run(Config, Ts), + + ok. + format_error(E) -> lists:flatten(erl_lint:format_error(E)). -- cgit v1.2.1