File 0740-Fix-FUNCTION_ARITY-for-a-bracket-only-first-argument.patch of Package erlang
From e6f8747509f35298d17359fcc73f741d7153394a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 17 Feb 2026 05:47:09 +0100
Subject: [PATCH] Fix ?FUNCTION_ARITY for a bracket-only first argument
`?FUNCTION_ARITY` would evaluate to one less the actual arity if
the first argument of the function were a bracket-only pattern,
as in the following example:
foo([]) -> ?FUNCTION_ARITY.
Fixes #10705
---
lib/stdlib/src/epp.erl | 7 ++++++-
lib/stdlib/test/epp_SUITE.erl | 10 +++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index 18870212a5..415cccc08c 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -1909,7 +1909,12 @@ update_fun_name_1([Tok|Toks], L, FA, St) ->
update_fun_name_1(Toks, L, FA, St)
end;
left ->
- update_fun_name_1(Toks, L+1, FA, St);
+ case FA of
+ {Name,0} ->
+ update_fun_name_1(Toks, L+1, {Name,1}, St);
+ {_,_} ->
+ update_fun_name_1(Toks, L+1, FA, St)
+ end;
right when L =:= 1 ->
FA;
right ->
diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl
index bb8e344e12..095197dbb8 100644
--- a/lib/stdlib/test/epp_SUITE.erl
+++ b/lib/stdlib/test/epp_SUITE.erl
@@ -1807,7 +1807,15 @@ function_macro(Config) ->
"b(?FUNCTION_ARITY, ?__) -> ok.\n"
"c(?FF) -> ok.\n"
"t() -> a(1, 2), b(3, 1, 2), c(c, 2), ok.\n">>,
- ok}
+ ok},
+
+ {f_5,
+ <<"a([]) -> 1 = ?FUNCTION_ARITY.\n"
+ "b({}) -> 1 = ?FUNCTION_ARITY.\n"
+ "c([], []) -> 2 = ?FUNCTION_ARITY.\n"
+ "d([], _) -> 2 = ?FUNCTION_ARITY.\n"
+ "t() -> a([]), b({}), c([], []), d([], 42), ok.\n">>,
+ ok}
],
[] = run(Config, Ts),
--
2.51.0