Skip to content

Commit

Permalink
Deprecate old-style catch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
richcarl committed Jan 10, 2025
1 parent 3e7f126 commit 8df7d03
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/stdlib/src/erl_lint.erl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,14 @@ format_error_1({deprecated_builtin_type, {Name, Arity},
end,
{~"type ~w/~w is deprecated and will be removed in ~s; use ~s",
[Name, Arity, Rel, UseS]};
format_error_1({not_exported_opaque, {TypeName, Arity}}) ->
format_error_1(deprecated_catch) ->
~"""
'catch ...' is deprecated and will be removed in a
future version of Erlang/OTP; please use 'try ... catch ... end' instead.
Compile directive 'nowarn_deprecated_catch' can be used to suppress
warnings in selected modules.
""";
format_error_1({not_exported_opaque, {TypeName, Arity}}) ->
{~"opaque type ~tw~s is not exported",
[TypeName, gen_type_paren(Arity)]};
format_error_1({bad_dialyzer_attribute,Term}) ->
Expand Down Expand Up @@ -830,6 +837,7 @@ bool_options() ->
{deprecated_function,true},
{deprecated_type,true},
{deprecated_callback,true},
{deprecated_catch,false},
{obsolete_guard,true},
{untyped_record,false},
{missing_spec,false},
Expand Down Expand Up @@ -2823,7 +2831,11 @@ expr({'try',Anno,Es,Scs,Ccs,As}, Vt, St0) ->
expr({'catch',Anno,E}, Vt, St0) ->
%% No new variables added, flag new variables as unsafe.
{Evt,St} = expr(E, Vt, St0),
{vtupdate(vtunsafe({'catch',Anno}, Evt, Vt), Evt),St};
St1 = case is_warn_enabled(deprecated_catch, St) of
true -> add_warning(Anno, deprecated_catch, St);
false -> St
end,
{vtupdate(vtunsafe({'catch',Anno}, Evt, Vt), Evt),St1};
expr({match,_Anno,P,E}, Vt, St0) ->
{Evt,St1} = expr(E, Vt, St0),
{Pvt,Pnew,St} = pattern(P, vtupdate(Evt, Vt), St1),
Expand Down

0 comments on commit 8df7d03

Please sign in to comment.