Skip to content

Commit bb5a666

Browse files
author
José Valim
committed
Raise for capture outside of function, closes #8516
1 parent 1492ceb commit bb5a666

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/elixir/src/elixir_expand.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ expand({'&', Meta, [Arg]}, E) ->
211211
is_atom(Remote) andalso
212212
elixir_lexical:record_remote(Remote, Fun, Arity, ?key(E, function), ?line(Meta), ?key(E, lexical_tracker)),
213213
{{'&', Meta, [{'/', [], [{{'.', [], [Remote, Fun]}, [], []}, Arity]}]}, EE};
214+
{{local, Fun, Arity}, #{function := nil}} ->
215+
form_error(Meta, ?key(E, file), ?MODULE, {undefined_local_capture, Fun, Arity});
214216
{{local, Fun, Arity}, EE} ->
215217
{{'&', Meta, [{'/', [], [{Fun, [], nil}, Arity]}]}, EE};
216218
{expand, Expr, EE} ->
@@ -1179,7 +1181,8 @@ format_error({nested_comparison, CompExpr}) ->
11791181
"Instead, consider joining together each comparison segment with an \"and\", e.g.\n\n"
11801182
" x < y and y < z\n\n"
11811183
"You wrote: ~ts", [String]);
1182-
1184+
format_error({undefined_local_capture, Fun, Arity}) ->
1185+
io_lib:format("undefined function ~ts/~B", [Fun, Arity]);
11831186
format_error(caller_not_allowed) ->
11841187
"__CALLER__ is available only inside defmacro and defmacrop";
11851188
format_error(stacktrace_not_allowed) ->

0 commit comments

Comments
 (0)