Skip to content

Commit d9a639e

Browse files
committed
debugger: Fix unbounded error in interpreted module
Fix #10057. When updating a record, the previous logic in `remove_temporary_bindings/2` could remove bindings that are still useful. Now only bindings that did not exist before the update are eligible for removal.
1 parent ccff599 commit d9a639e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/debugger/src/dbg_ieval.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ expr({record_update,Line,Es},Bs,#ieval{level=Le}=Ieval0) ->
681681
Ieval = Ieval0#ieval{top=false, line=Line, level=Le+1},
682682
Seq = fun(E, {_, _, Bs1}) -> expr(E, Bs1, Ieval) end,
683683
{value,Value,Bs1} = lists:foldl(Seq, {value, true, Bs}, Es),
684-
{value,Value,remove_temporary_bindings(Bs1)};
684+
{value,Value,remove_temporary_bindings(Bs1, Bs)};
685685

686686
%% A block of statements
687687
expr({block,Line,Es},Bs,Ieval) ->
@@ -1846,8 +1846,9 @@ add_binding(N,Val,[B1|Bs]) ->
18461846
add_binding(N,Val,[]) ->
18471847
[{N,Val}].
18481848

1849-
remove_temporary_bindings(Bs0) ->
1850-
[{Var,Val} || {Var, Val} <- Bs0, hd(atom_to_list(Var)) =/= $%].
1849+
remove_temporary_bindings(Bs0, Bs) ->
1850+
[{Var,Val} || {Var, Val} <- Bs0, hd(atom_to_list(Var)) =/= $% orelse
1851+
lists:keymember(Var, 1, Bs)].
18511852

18521853
%% get_stacktrace() -> Stacktrace
18531854
%% Return the latest stacktrace for the process.

lib/debugger/test/record_SUITE.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
init_per_testcase/2,end_per_testcase/2,
3030
init_per_suite/1,end_per_suite/1,
3131
errors/1,record_test/1,eval_once/1,
32-
nested_in_guard/1]).
32+
nested_in_guard/1, gh10057/1]).
3333

3434
-export([debug/0]).
3535

@@ -51,7 +51,7 @@ end_per_group(_GroupName, Config) ->
5151

5252

5353
cases() ->
54-
[errors, record_test, eval_once, nested_in_guard].
54+
[errors, record_test, eval_once, nested_in_guard, gh10057].
5555

5656
init_per_testcase(_Case, Config) ->
5757
test_lib:interpret(?MODULE),
@@ -320,6 +320,14 @@ do_nested_in_guard(F) ->
320320
not_ok
321321
end.
322322

323+
gh10057(_Config) ->
324+
N = #foo{b = #bar{c = '$expecting_key'}},
325+
do_gh10057(N, ss),
326+
ok.
327+
328+
do_gh10057(#foo{b = #bar{c = '$expecting_key'} = B} = N, Key) ->
329+
N#foo{a = {map, Key},b = B#bar{c = Key}}.
330+
323331
id(I) ->
324332
I.
325333

0 commit comments

Comments
 (0)