Skip to content

Commit b38327e

Browse files
committed
fixup! Add options for silencing warnings for behaviours
1 parent 0f24dee commit b38327e

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

lib/compiler/src/compile.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ value are listed.
736736
this kind of warning for the types in `Types`, where `Types` is a tuple
737737
`{TypeName,Arity}` or a list of such tuples.
738738

739+
- **`nowarn_behaviours`** - By default, warnings are emitted for issues
740+
with behaviours. Use this option to turn off all warnings of this kind.
741+
739742
- **`nowarn_conflicting_behaviours`** - By default, warnings are emitted when
740743
a module opts in to multiple behaviours that share the names of one or more
741744
callback functions. Use this option to turn off this kind of warning.

lib/stdlib/src/erl_lint.erl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,10 @@ start(File, Opts) ->
823823
bool_option(warn_update_literal, nowarn_update_literal,
824824
true, Opts)},
825825
%% Behaviour warnings.
826+
{behaviours,
827+
bool_option(warn_behaviours,
828+
nowarn_behaviours,
829+
true, Opts)},
826830
{conflicting_behaviours,
827831
bool_option(warn_conflicting_behaviours,
828832
nowarn_conflicting_behaviours,
@@ -1256,8 +1260,13 @@ post_traversal_check(Forms, St0) ->
12561260
%% check_behaviour(State0) -> State
12571261
%% Check that the behaviour attribute is valid.
12581262

1259-
check_behaviour(St0) ->
1260-
behaviour_check(St0#lint.behaviour, St0).
1263+
check_behaviour(St) ->
1264+
case is_warn_enabled(behaviours, St) of
1265+
true ->
1266+
behaviour_check(St#lint.behaviour, St);
1267+
false ->
1268+
St
1269+
end.
12611270

12621271
%% behaviour_check([{Anno,Behaviour}], State) -> State'
12631272
%% Check behaviours for existence and defined functions.

lib/stdlib/test/erl_lint_SUITE.erl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,10 +3472,14 @@ behaviour_basic(Config) when is_list(Config) ->
34723472
],
34733473
[] = run(Config, Ts),
34743474

3475-
Subst = #{behaviour1 => [nowarn_undefined_behaviour_func],
3476-
behaviour2 => [nowarn_undefined_behaviour_func],
3477-
behaviour4 => [nowarn_undefined_behaviour_func]},
3475+
Subst0 = #{behaviour1 => [nowarn_undefined_behaviour_func],
3476+
behaviour2 => [nowarn_undefined_behaviour_func],
3477+
behaviour4 => [nowarn_undefined_behaviour_func]},
3478+
[] = run(Config, rewrite(Ts, Subst0)),
3479+
3480+
Subst = #{K => [nowarn_behaviours] || K := _ <- Subst0},
34783481
[] = run(Config, rewrite(Ts, Subst)),
3482+
34793483
ok.
34803484

34813485
%% Basic tests with multiple behaviours.
@@ -3781,13 +3785,16 @@ otp_11861(Conf) when is_list(Conf) ->
37813785
],
37823786
[] = run(Conf, Ts),
37833787

3784-
Subst = #{otp_11861_1 => [nowarn_conflicting_behaviours],
3785-
otp_11861_11 => [nowarn_ill_defined_behaviour_callbacks],
3786-
otp_11861_12 => [nowarn_undefined_behaviour],
3787-
otp_11861_13 => [nowarn_undefined_behaviour],
3788-
otp_11861_17 => [nowarn_undefined_behaviour_callbacks],
3789-
otp_11861_19 => [nowarn_ill_defined_optional_callbacks]
3790-
},
3788+
Subst0 = #{otp_11861_1 => [nowarn_conflicting_behaviours],
3789+
otp_11861_11 => [nowarn_ill_defined_behaviour_callbacks],
3790+
otp_11861_12 => [nowarn_undefined_behaviour],
3791+
otp_11861_13 => [nowarn_undefined_behaviour],
3792+
otp_11861_17 => [nowarn_undefined_behaviour_callbacks],
3793+
otp_11861_19 => [nowarn_ill_defined_optional_callbacks]
3794+
},
3795+
[] = run(Conf, rewrite(Ts, Subst0)),
3796+
3797+
Subst = #{K => [nowarn_behaviours] || K := _ <- Subst0},
37913798
[] = run(Conf, rewrite(Ts, Subst)),
37923799

37933800
true = code:set_path(CodePath),

0 commit comments

Comments
 (0)