@@ -49,7 +49,6 @@ each_clause(Meta, { rescue, [Condition|T], Expr }, S) ->
49
49
end
50
50
end ;
51
51
_ ->
52
- validate_rescue_access (Meta , Condition , S ),
53
52
each_clause (Meta , { 'catch' , [error , Condition |T ], Expr }, S )
54
53
end ;
55
54
@@ -65,8 +64,12 @@ each_clause(Meta, {Key,_,_}, S) ->
65
64
normalize_rescue (Meta , List , S ) when is_list (List ) ->
66
65
normalize_rescue (Meta , { in , Meta , [{ '_' , Meta , nil }, List ] }, S );
67
66
67
+ % % rescue _
68
+ normalize_rescue (_ , { '_' , _ , Atom }, _S ) when is_atom (Atom ) ->
69
+ false ;
70
+
68
71
% % 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 ) ->
70
73
normalize_rescue (Meta , { in , Meta , [Rescue , { '_' , Meta , nil }] }, S );
71
74
72
75
% % rescue var in [Exprs]
@@ -85,22 +88,13 @@ normalize_rescue(_, { in, Meta, [Left, Right] }, S) ->
85
88
end
86
89
end ;
87
90
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
-
98
91
normalize_rescue (Meta , Condition , S ) ->
99
92
case elixir_translator :translate_each (Condition , S # elixir_scope {context = match }) of
100
93
{ { atom , _ , Atom }, _ } ->
101
94
normalize_rescue (Meta , { in , Meta , [{ '_' , Meta , nil }, [Atom ]] }, S );
102
95
_ ->
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" )
104
98
end .
105
99
106
100
% % Convert rescue clauses into guards.
@@ -242,24 +236,6 @@ erlang_rescue_guard_for(Meta, Var, 'Elixir.ErlangError') ->
242
236
] },
243
237
{ 'or' , Meta , [IsNotTuple , IsException ] }.
244
238
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
-
263
239
% % Helpers
264
240
265
241
format_error ({ rescue_no_match , Var , Alias }) ->
0 commit comments