From 31f7fbe4b71b79ba27efc2a5085746c4011ceb8f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 2 Aug 2022 09:44:07 +0200 Subject: [PATCH] Prometheus.Erlang: Fix Kernel.Utils.defdelegate usage for Elixir 1.14 Elixir 1.14 changed Kernel.Utils.defdelegate/2 into Kernel.Utils.defdelegate_each/2 --- lib/prometheus/erlang.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/prometheus/erlang.ex b/lib/prometheus/erlang.ex index 285e41b..a90e9c0 100644 --- a/lib/prometheus/erlang.ex +++ b/lib/prometheus/erlang.ex @@ -14,13 +14,19 @@ defmodule Prometheus.Erlang do end end + if Version.match?(System.version(), "< 1.14.0-rc.0") do + def defdelegate_each(fun, opts), do: Kernel.Utils.defdelegate(fun, opts) + else + def defdelegate_each(fun, opts), do: Kernel.Utils.defdelegate_each(fun, opts) + end + defmacro delegate(fun, opts \\ []) do fun = Macro.escape(fun, unquote: true) quote bind_quoted: [fun: fun, opts: opts] do target = Keyword.get(opts, :to, @erlang_module) - {name, args, as, as_args} = Kernel.Utils.defdelegate(fun, opts) + {name, args, as, as_args} = defdelegate_each(fun, opts) def unquote(name)(unquote_splicing(args)) do Prometheus.Error.with_prometheus_error( @@ -36,7 +42,7 @@ defmodule Prometheus.Erlang do quote bind_quoted: [fun: fun, opts: opts] do target = Keyword.get(opts, :to, @erlang_module) - {name, args, as, [spec | as_args]} = Kernel.Utils.defdelegate(fun, opts) + {name, args, as, [spec | as_args]} = defdelegate_each(fun, opts) def unquote(name)(unquote_splicing(args)) do {registry, name, labels} = Metric.parse_spec(unquote(spec))