|
3 | 3 | -module(elixir_translator). |
4 | 4 | -export([forms/4, 'forms!'/4]). |
5 | 5 | -export([translate/2, translate_each/2, translate_arg/2, |
6 | | - translate_args/2, translate_apply/7, translate_fn/3]). |
| 6 | + translate_args/2, translate_apply/7]). |
7 | 7 | -import(elixir_scope, [umergev/2, umergec/2, umergea/2]). |
8 | 8 | -import(elixir_errors, [syntax_error/3, syntax_error/4, |
9 | 9 | compile_error/3, compile_error/4, |
@@ -300,9 +300,13 @@ translate_each({ 'var!', Meta, [_, _] }, S) -> |
300 | 300 |
|
301 | 301 | %% Functions |
302 | 302 |
|
| 303 | +translate_each({ '&', Meta, [Arg] }, S) -> |
| 304 | + assert_no_match_or_guard_scope(Meta, '&', S), |
| 305 | + elixir_fn:capture(Meta, Arg, S); |
| 306 | + |
303 | 307 | translate_each({ fn, Meta, [[{do, { '->', _, Pairs }}]] }, S) -> |
304 | 308 | assert_no_match_or_guard_scope(Meta, 'fn', S), |
305 | | - translate_fn(Meta, Pairs, S); |
| 309 | + elixir_fn:fn(Meta, Pairs, S); |
306 | 310 |
|
307 | 311 | %% Comprehensions |
308 | 312 |
|
@@ -562,24 +566,6 @@ no_alias_expansion(Other) -> |
562 | 566 | is_atom_tuple({ atom, _, _ }) -> true; |
563 | 567 | is_atom_tuple(_) -> false. |
564 | 568 |
|
565 | | -%% Function |
566 | | - |
567 | | -translate_fn(Meta, Clauses, S) -> |
568 | | - Transformer = fun({ ArgsWithGuards, CMeta, Expr }, Acc) -> |
569 | | - { Args, Guards } = elixir_clauses:extract_splat_guards(ArgsWithGuards), |
570 | | - elixir_clauses:assigns_block(?line(CMeta), fun elixir_translator:translate/2, Args, [Expr], Guards, umergec(S, Acc)) |
571 | | - end, |
572 | | - |
573 | | - { TClauses, NS } = lists:mapfoldl(Transformer, S, Clauses), |
574 | | - Arities = [length(Args) || { clause, _Line, Args, _Guards, _Exprs } <- TClauses], |
575 | | - |
576 | | - case length(lists:usort(Arities)) of |
577 | | - 1 -> |
578 | | - { { 'fun', ?line(Meta), { clauses, TClauses } }, umergec(S, NS) }; |
579 | | - _ -> |
580 | | - syntax_error(Meta, S#elixir_scope.file, "cannot mix clauses with different arities in function definition") |
581 | | - end. |
582 | | - |
583 | 569 | %% Locals |
584 | 570 |
|
585 | 571 | translate_local(Meta, Name, Args, #elixir_scope{local=nil,function=nil} = S) -> |
|
0 commit comments