diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index 7f07a1294e8..9033d65cfda 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -636,9 +636,14 @@ defmodule Protocol do built_in_plus_any = [Any] ++ for {mod, _guard} <- built_in(), do: mod structs = types -- built_in_plus_any - {select_impl, definitions} = List.keytake(definitions, {:__select_impl__, 1}, 0) - {dispatch_impl, definitions} = List.keytake(definitions, {:__dispatch_impl__, 4}, 0) - {select_struct, definitions} = List.keytake(definitions, {:__select_struct__, 1}, 0) + {select_impl, definitions} = + keytake_definition(definitions, {:__select_impl__, 1}, protocol) + + {dispatch_impl, definitions} = + keytake_definition(definitions, {:__dispatch_impl__, 4}, protocol) + + {select_struct, definitions} = + keytake_definition(definitions, {:__select_struct__, 1}, protocol) protocol_funs = get_protocol_functions(protocol_def) @@ -673,6 +678,22 @@ defmodule Protocol do end end + # The definitions below are generated by defprotocol. If any of them is + # missing, the beam was compiled with an incompatible version of Elixir. + defp keytake_definition(definitions, {name, arity}, protocol) do + case List.keytake(definitions, {name, arity}, 0) do + nil -> + raise ArgumentError, + "cannot consolidate protocol #{Macro.inspect_atom(:literal, protocol)}: " <> + "it does not define #{name}/#{arity}, which means it was compiled " <> + "with an incompatible version of Elixir, please recompile the protocol " <> + "with the current version" + + {entry, definitions} -> + {entry, definitions} + end + end + defp new_signatures(definitions, protocol_funs, protocol, types, structs) do alias Module.Types.Descr types_minus_any = List.delete(types, Any) diff --git a/lib/mix/lib/mix/compilers/elixir.ex b/lib/mix/lib/mix/compilers/elixir.ex index 3ee3e388a44..25964880fad 100644 --- a/lib/mix/lib/mix/compilers/elixir.ex +++ b/lib/mix/lib/mix/compilers/elixir.ex @@ -5,7 +5,7 @@ defmodule Mix.Compilers.Elixir do @moduledoc false - @manifest_vsn 37 + @manifest_vsn 38 @checkpoint_vsn 5 import Record