@@ -49,7 +49,6 @@ each_clause(Meta, { rescue, [Condition|T], Expr }, S) ->
4949 end
5050 end ;
5151 _ ->
52- validate_rescue_access (Meta , Condition , S ),
5352 each_clause (Meta , { 'catch' , [error , Condition |T ], Expr }, S )
5453 end ;
5554
@@ -65,8 +64,12 @@ each_clause(Meta, {Key,_,_}, S) ->
6564normalize_rescue (Meta , List , S ) when is_list (List ) ->
6665 normalize_rescue (Meta , { in , Meta , [{ '_' , Meta , nil }, List ] }, S );
6766
67+ % % rescue _
68+ normalize_rescue (_ , { '_' , _ , Atom }, _S ) when is_atom (Atom ) ->
69+ false ;
70+
6871% % rescue var -> var in _
69- normalize_rescue (_ , { Name , Meta , Atom } = Rescue , S ) when is_atom (Name ), is_atom (Atom ), Name /= '_' ->
72+ normalize_rescue (_ , { Name , Meta , Atom } = Rescue , S ) when is_atom (Name ), is_atom (Atom ) ->
7073 normalize_rescue (Meta , { in , Meta , [Rescue , { '_' , Meta , nil }] }, S );
7174
7275% % rescue var in [Exprs]
@@ -85,22 +88,13 @@ normalize_rescue(_, { in, Meta, [Left, Right] }, S) ->
8588 end
8689 end ;
8790
88- normalize_rescue (_ , { '=' , Meta , [{ '__aliases__' , _ , _ } = Alias , { Name , _ , Atom } = Var ] }, S )
89- when is_atom (Name ) and is_atom (Atom ) ->
90- elixir_errors :handle_file_warning (S # elixir_scope .file , { Meta , ? MODULE , { rescue_no_match , Var , Alias } }),
91- false ;
92-
93- normalize_rescue (_ , { '=' , Meta , [{ Name , _ , Atom } = Var , { '__aliases__' , _ , _ } = Alias ] }, S )
94- when is_atom (Name ) and is_atom (Atom ) ->
95- elixir_errors :handle_file_warning (S # elixir_scope .file , { Meta , ? MODULE , { rescue_no_match , Var , Alias } }),
96- false ;
97-
9891normalize_rescue (Meta , Condition , S ) ->
9992 case elixir_translator :translate_each (Condition , S # elixir_scope {context = match }) of
10093 { { atom , _ , Atom }, _ } ->
10194 normalize_rescue (Meta , { in , Meta , [{ '_' , Meta , nil }, [Atom ]] }, S );
10295 _ ->
103- false
96+ elixir_errors :syntax_error (Meta , S # elixir_scope .file , " invalid rescue clause. The clause should match on an alias, "
97+ " a variable or be in the `var in [alias]` format" )
10498 end .
10599
106100% % Convert rescue clauses into guards.
@@ -242,24 +236,6 @@ erlang_rescue_guard_for(Meta, Var, 'Elixir.ErlangError') ->
242236 ] },
243237 { 'or' , Meta , [IsNotTuple , IsException ] }.
244238
245- % % Validate rescue access
246-
247- validate_rescue_access (Meta , { '=' , _ , [Left , Right ] }, S ) ->
248- validate_rescue_access (Meta , Left , S ),
249- validate_rescue_access (Meta , Right , S );
250-
251- validate_rescue_access (Meta , { { '.' , _ , ['Elixir.Kernel' , 'access' ] }, _ , [Element , _ ] }, S ) ->
252- case elixir_translator :translate_each (Element , S ) of
253- { { atom , _ , Atom }, _ } ->
254- case lists :member (Atom , erlang_rescues ()) of
255- false -> [];
256- true -> elixir_errors :syntax_error (Meta , S # elixir_scope .file , " cannot (yet) pattern match against erlang exceptions" )
257- end ;
258- _ -> []
259- end ;
260-
261- validate_rescue_access (_ , _ , _ ) -> [].
262-
263239% % Helpers
264240
265241format_error ({ rescue_no_match , Var , Alias }) ->
0 commit comments