@@ -107,6 +107,14 @@ do_receive(Meta, {Key, _}, _Acc, E) ->
107
107
'try' (Meta , KV , E ) when not is_list (KV ) ->
108
108
compile_error (Meta , ? m (E , file ), " invalid arguments for try" );
109
109
'try' (Meta , KV , E ) ->
110
+ RaiseError = fun (Kind ) ->
111
+ compile_error (Meta , ? m (E , file ), " duplicated ~ts clauses given for try" , [Kind ])
112
+ end ,
113
+ ok = assert_at_most_once ('do' , KV , 0 , RaiseError ),
114
+ ok = assert_at_most_once ('rescue' , KV , 0 , RaiseError ),
115
+ ok = assert_at_most_once ('catch' , KV , 0 , RaiseError ),
116
+ ok = assert_at_most_once ('else' , KV , 0 , RaiseError ),
117
+ ok = assert_at_most_once ('after' , KV , 0 , RaiseError ),
110
118
{lists :map (fun (X ) -> do_try (Meta , X , E ) end , KV ), E }.
111
119
112
120
do_try (_Meta , {'do' , Expr }, E ) ->
@@ -214,3 +222,11 @@ expand_without_export(Meta, Kind, Fun, {Key, Clauses}, E) when is_list(Clauses)
214
222
{Key , lists :map (Transformer , Clauses )};
215
223
expand_without_export (Meta , Kind , _Fun , {Key , _ }, E ) ->
216
224
compile_error (Meta , ? m (E , file ), " expected -> clauses for ~ts in ~ts " , [Key , Kind ]).
225
+
226
+ assert_at_most_once (_Kind , [], _Count , _Fun ) -> ok ;
227
+ assert_at_most_once (Kind , [{Kind , _ } | _ ], 1 , ErrorFun ) ->
228
+ ErrorFun (Kind );
229
+ assert_at_most_once (Kind , [{Kind , _ } | Rest ], Count , Fun ) ->
230
+ assert_at_most_once (Kind , Rest , Count + 1 , Fun );
231
+ assert_at_most_once (Kind , [_ | Rest ], Count , Fun ) ->
232
+ assert_at_most_once (Kind , Rest , Count , Fun ).
0 commit comments