File 1330-v3_core-Ensure-that-variable-_-don-t-end-up-in-debug.patch of Package erlang
From f52a49dd01fdfee38607888e188e2fecc2c2c7e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 2 Sep 2025 05:44:02 +0200
Subject: [PATCH 1/2] v3_core: Ensure that variable `_` don't end up in
debug_line
The `_` variable in Erlang code should always be translated to
a new variable in Core Erlang. Because of Core Erlang's proper
scoping, using `_` as a Core Erlang variable will usually work,
but can later end up the in the debug information produced by
`beam_debug_info`.
---
lib/compiler/src/v3_core.erl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl
index bd87f3ac5e..98b4f26cbc 100644
--- a/lib/compiler/src/v3_core.erl
+++ b/lib/compiler/src/v3_core.erl
@@ -3503,6 +3503,8 @@ upat_bin([], _, _, St) -> {[],[],[],[],St}.
upat_element(#ibitstr{val=H0,size=Sz0}=Seg, Ks, Bs0, St0) ->
{H1,Hg,Hv,[],St1} = upattern(H0, Ks, St0),
Bs1 = case H0 of
+ #c_var{name='_'} ->
+ Bs0;
#c_var{name=Hname} ->
case H1 of
#c_var{name=Hname} ->
@@ -3633,8 +3635,12 @@ ren_pat(P, Ks0, {_,_}=Subs0, St0) ->
ren_pat_bin([#ibitstr{val=Val0,size=Sz0}=E|Es0], Ks, Isub0, Osub0, St0) ->
Sz = ren_get_subst(Sz0, Isub0),
{Val,{_,Osub1},St1} = ren_pat(Val0, Ks, {Isub0,Osub0}, St0),
- Isub1 = case Val0 of
- #c_var{} ->
+ Isub1 = case {Val0, Val} of
+ {#c_var{name='_'}, _} ->
+ Isub0;
+ {#c_var{name=Name}, #c_var{name=Name}} ->
+ Isub0;
+ {#c_var{}, _} ->
[#iset{var=Val0,arg=Val}|Isub0];
_ ->
Isub0
--
2.51.0