Skip to content

Commit b6d97c3

Browse files
author
José Valim
committed
Fix bootstraping issues
1 parent 6daca1b commit b6d97c3

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,11 @@ defmodule Kernel do
20742074
attr = Module.get_attribute(env_module(env), name, stack)
20752075
:erlang.element(1, :elixir_quote.escape(attr, false))
20762076
false ->
2077-
quote do: Module.get_attribute(__MODULE__, unquote(name), unquote(Macro.escape(stack)))
2077+
escaped = case stack do
2078+
[] -> []
2079+
_ -> Macro.escape(stack)
2080+
end
2081+
quote do: Module.get_attribute(__MODULE__, unquote(name), unquote(escaped))
20782082
end
20792083
end
20802084

@@ -2655,14 +2659,7 @@ defmodule Kernel do
26552659

26562660
right = case bootstraped?(Macro.Env) do
26572661
true -> Macro.expand(right, __CALLER__)
2658-
false ->
2659-
case right do
2660-
# For bootstrapping we special case @attributes
2661-
{ :@, _, [{ name, _, atom }] } when is_atom(name) and is_atom(atom) ->
2662-
Module.get_attribute(env_module(__CALLER__), name, true)
2663-
_ ->
2664-
right
2665-
end
2662+
false -> right
26662663
end
26672664

26682665
case right do
@@ -2684,7 +2681,8 @@ defmodule Kernel do
26842681
in_range(left, Macro.escape(first), Macro.escape(last))
26852682
_ ->
26862683
raise ArgumentError, message: <<"invalid args for operator in, it expects a compile time list ",
2687-
"or range on the right side when used in guard expressions">>
2684+
"or range on the right side when used in guard expressions, got: ",
2685+
Macro.to_string(right) :: binary>>
26882686
end
26892687
end
26902688

lib/elixir/lib/macro.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ defmodule Macro do
362362
end
363363

364364
# Binary ops
365-
def to_string({ op, _, [left, right] } = ast, fun) when op in @binary_ops do
365+
def to_string({ op, _, [left, right] } = ast, fun) when op in unquote(@binary_ops) do
366366
fun.(ast, op_to_string(left, fun, op, :left) <> " #{op} " <> op_to_string(right, fun, op, :right))
367367
end
368368

@@ -377,7 +377,7 @@ defmodule Macro do
377377
fun.(ast, "not " <> to_string(arg, fun))
378378
end
379379

380-
def to_string({ op, _, [arg] } = ast, fun) when op in @unary_ops do
380+
def to_string({ op, _, [arg] } = ast, fun) when op in unquote(@unary_ops) do
381381
fun.(ast, atom_to_binary(op) <> to_string(arg, fun))
382382
end
383383

@@ -421,7 +421,7 @@ defmodule Macro do
421421
@kw_keywords [:do, :catch, :rescue, :after, :else]
422422

423423
defp kw_blocks?([_|_] = kw) do
424-
Enum.all?(kw, &match?({x, _} when x in @kw_keywords, &1))
424+
Enum.all?(kw, &match?({x, _} when x in unquote(@kw_keywords), &1))
425425
end
426426
defp kw_blocks?(_), do: false
427427

@@ -488,7 +488,7 @@ defmodule Macro do
488488
"(" <> to_string(expr, fun) <> ")"
489489
end
490490

491-
defp op_to_string({ op, _, [_, _] } = expr, fun, parent_op, side) when op in @binary_ops do
491+
defp op_to_string({ op, _, [_, _] } = expr, fun, parent_op, side) when op in unquote(@binary_ops) do
492492
{ parent_assoc, parent_prec } = binary_op_props(parent_op)
493493
{ _, prec } = binary_op_props(op)
494494
cond do

0 commit comments

Comments
 (0)