Raise an error when trying to make private macros overridable (#4856)

This is not supported as of today because of bugs regarding defoverride
and macros, but we decided to not support overriding private macros at
all so let's raise a nice error message.

For the record, supporting overridable private macros would be very
annoying since we rely on function names and the such for implementing
overridable stuff, and for private macros we just generate functions on
the fly.
This commit is contained in:
Andrea Leopardi
2016-06-24 00:21:25 +02:00
committed by GitHub
parent 2cab3369aa
commit 3c88c16b0f
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -830,6 +830,10 @@ defmodule Module do
false ->
{name, arity} = tuple
raise "cannot make function #{name}/#{arity} overridable because it was not defined"
{{{:def, {name, arity}}, :defmacrop, _line, _file, _check, _location, _defaults}, _clauses} ->
raise ArgumentError,
"cannot make private macro #{name}/#{arity} overridable, overriding " <>
"private macros is not supported"
clause ->
neighbours =
if :elixir_compiler.get_opt(:internal) do
@@ -189,4 +189,18 @@ defmodule Kernel.OverridableTest do
test "overridable macros" do
assert Overridable.overridable_macro(1) == 1101
end
test "private macros can't be overridden" do
message =
"cannot make private macro foo/0 overridable, overriding " <>
"private macros is not supported"
assert_raise ArgumentError, message, fn ->
Code.eval_string """
defmodule Foo do
defmacrop foo, do: 1
defoverridable foo: 0
end
"""
end
end
end