-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix infinite loop in shell caused by record with recursive typespec #1489
Conversation
Hi, Thanks for pointing out the bug. I don't think this is the best correction, though. I'd rather see: diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl
Another case we missed when changing the representation of typed Best regards |
Hi, [Sorry for the ugly indentation.] Thanks for pointing out the bug. I don't think this is the best correction, though. I'd rather see: diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl
index 6eafc7b..9b72312 100644
--- a/lib/stdlib/src/shell.erl
+++ b/lib/stdlib/src/shell.erl
@@ -758,6 +758,8 @@ used_records({record,_,R,Name,Ups}) ->
{name, Name, [R | Ups]};
used_records({record_field,_,R,F}) -> % illegal
{expr, [R | F]};
+used_records({typed_record_field,Field,_Type}) ->
+ used_records(Field);
used_records({call,_,{atom,_,record},[A,{atom,_,Name}]}) ->
{name, Name, A};
used_records({call,_,{atom,_,is_record},[A,{atom,_,Name}]}) -> Another case we missed when changing the representation of typed Best regards |
@uabboli This certainly looks nicer, but does not work when there are other record fields:
results in:
with proposed fix result is as expected:
|
I see. Forget my last suggestion; it's no good. Your patch tests if record Name has already been seen. Note however Extending your example a bit: -module(bug).
-export([t/0, t2/0]).
-record(r0,{f0}).
-record(r,{f :: #r{} | undefined, f0 :: #r0{}}).
t() ->
#r{f=#r{f=undefined, f0 = #r0{f0 = v}}}.
-record(r2, {}).
t2() ->
#r2{}. Now try: > erl
Eshell V9.0 (abort with ^G)
1> c(bug).
{ok,bug}
2> rr(bug).
[r,r0,r2]
3> (#r{f = #r2{}})#r{f = 18}.
* 1: record r2 undefined
4> |
@uabboli good point
|
Looks good. A test in shell_SUITE.erl would be nice. It should be possible to The patch cannot make it into Erlang/OTP 20.0 since the code is |
Added It turns out that if already seen records are always skipped that messes up When Erlang/OTP 20.0 is out I will rebase the patch on maint. |
d922e54
to
fcdb10c
Compare
If record with recursive typespec such as -record(r,{f :: #r{} | undefined}). is used in interactive shell it stucks in inifinite loop when trying to find definitions for all records used in expression.
@uabboli rebased onto |
Thanks. I'll merge the branch soon. |
Merged commit 693691a into erlang:maint. |
If record with recursive typespec such as
-record(r,{f :: #r{} | undefined}).
is used in interactive shell it stucks in inifinite loop when trying to find definitions for all records used in expression.
For example following module definition:
leads to this result in interactive shell: