Skip to content

Commit 999a535

Browse files
author
José Valim
committed
Manually call check_command before eval, closes #2449
1 parent a726dd8 commit 999a535

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/elixir/src/elixir.erl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,19 @@ eval_forms(Tree, Binding, Env, Scope) ->
155155
{atom, _, Atom} ->
156156
{Atom, Binding, NewEnv, NewScope};
157157
_ ->
158-
{value, Value, NewBinding} = erl_eval(Erl, ParsedBinding),
158+
{value, Value, NewBinding} = erl_eval(Erl, ParsedBinding, Env),
159159
{Value, elixir_scope:dump_binding(NewBinding, NewScope), NewEnv, NewScope}
160160
end.
161161

162-
erl_eval(Erl, ParsedBinding) ->
162+
erl_eval(Erl, ParsedBinding, E) ->
163+
case erl_eval:check_command([Erl], ParsedBinding) of
164+
ok -> ok;
165+
{error, Desc} -> elixir_errors:handle_file_error(?m(E, file), Desc)
166+
end,
167+
163168
% Below must be all one line for locations to be the same when the stacktrace
164169
% needs to be extended to the full stacktrace.
165-
try erl_eval:expr(Erl, ParsedBinding) catch Class:Exception -> erlang:raise(Class, Exception, get_stacktrace()) end.
170+
try erl_eval:expr(Erl, ParsedBinding, none, none, none) catch Class:Exception -> erlang:raise(Class, Exception, get_stacktrace()) end.
166171

167172
get_stacktrace() ->
168173
Stacktrace = erlang:get_stacktrace(),

lib/elixir/test/elixir/code_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ defmodule CodeTest do
2828
assert Code.eval_string("var!(a, Sample) = 1") == {1, [{{:a,Sample},1}]}
2929
end
3030

31+
test :eval_binary_errors do
32+
msg = "nofile:2: a binary field without size is only allowed at the end of a binary pattern"
33+
assert_raise CompileError, msg, fn ->
34+
Code.eval_string("""
35+
foo = "foo"
36+
"\\"" <> bar <> "\\"" = foo
37+
""")
38+
end
39+
end
40+
3141
test :eval_with_unnamed_scopes do
3242
assert {%RuntimeError{}, [a: %RuntimeError{}]} =
3343
Code.eval_string("a = (try do (raise \"hello\") rescue e -> e end)")

0 commit comments

Comments
 (0)