<p dir="auto">It'd be nice if <code class="notranslate">displaysize(tty)</code> after <code class="notranslate">close(tty)</code> can throw an exception rather than segfault. MWE:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; tty = Base.TTY(fd(Base.Filesystem.open(&quot;/proc/self/fd/1&quot;, Base.Filesystem.JL_O_WRONLY)))
Base.TTY(RawFD(0x00000016) open, 0 bytes waiting)

julia&gt; displaysize(tty)
(43, 114)

julia&gt; close(tty)

julia&gt; displaysize(tty)

signal (11): Segmentation fault
in expression starting at REPL[4]:1
uv_tty_get_winsize at /workspace/srcdir/libuv/src/unix/tty.c:274
displaysize at ./stream.jl:478
jfptr_displaysize_2966 at /home/takafumi/repos/watch/julia/usr/lib/julia/sys.so (unknown line)
jl_apply at /home/takafumi/repos/watch/julia/src/julia.h:1694 [inlined]
do_call at /home/takafumi/repos/watch/julia/src/interpreter.c:369
eval_value at /home/takafumi/repos/watch/julia/src/interpreter.c:458
eval_stmt_value at /home/takafumi/repos/watch/julia/src/interpreter.c:409 [inlined]
eval_body at /home/takafumi/repos/watch/julia/src/interpreter.c:799
jl_interpret_toplevel_thunk at /home/takafumi/repos/watch/julia/src/interpreter.c:911
jl_toplevel_eval_flex at /home/takafumi/repos/watch/julia/src/toplevel.c:814
jl_toplevel_eval_flex at /home/takafumi/repos/watch/julia/src/toplevel.c:764
jl_toplevel_eval_in at /home/takafumi/repos/watch/julia/src/toplevel.c:843
eval at ./boot.jl:331
eval_user_input at /home/takafumi/repos/watch/julia/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:107
run_backend at /home/takafumi/.julia/packages/Revise/SefCg/src/Revise.jl:1042
#85 at ./task.jl:358
jl_apply at /home/takafumi/repos/watch/julia/src/julia.h:1694 [inlined]
start_task at /home/takafumi/repos/watch/julia/src/task.c:687
unknown function (ip: (nil))
Allocations: 14143307 (Pool: 14139964; Big: 3343); GC: 14"><pre class="notranslate">julia<span class="pl-k">&gt;</span> tty <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">TTY</span>(<span class="pl-c1">fd</span>(Base<span class="pl-k">.</span>Filesystem<span class="pl-k">.</span><span class="pl-c1">open</span>(<span class="pl-s"><span class="pl-pds">"</span>/proc/self/fd/1<span class="pl-pds">"</span></span>, Base<span class="pl-k">.</span>Filesystem<span class="pl-k">.</span>JL_O_WRONLY)))
Base<span class="pl-k">.</span><span class="pl-c1">TTY</span>(<span class="pl-c1">RawFD</span>(<span class="pl-c1">0x00000016</span>) open, <span class="pl-c1">0</span> bytes waiting)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">displaysize</span>(tty)
(<span class="pl-c1">43</span>, <span class="pl-c1">114</span>)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">close</span>(tty)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">displaysize</span>(tty)

signal (<span class="pl-c1">11</span>)<span class="pl-k">:</span> Segmentation fault
in expression starting at REPL[<span class="pl-c1">4</span>]<span class="pl-k">:</span><span class="pl-c1">1</span>
uv_tty_get_winsize at <span class="pl-k">/</span>workspace<span class="pl-k">/</span>srcdir<span class="pl-k">/</span>libuv<span class="pl-k">/</span>src<span class="pl-k">/</span>unix<span class="pl-k">/</span>tty<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">274</span>
displaysize at <span class="pl-k">./</span>stream<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">478</span>
jfptr_displaysize_2966 at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>usr<span class="pl-k">/</span>lib<span class="pl-k">/</span>julia<span class="pl-k">/</span>sys<span class="pl-k">.</span>so (unknown line)
jl_apply at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>julia<span class="pl-k">.</span>h<span class="pl-k">:</span><span class="pl-c1">1694</span> [inlined]
do_call at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>interpreter<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">369</span>
eval_value at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>interpreter<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">458</span>
eval_stmt_value at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>interpreter<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">409</span> [inlined]
eval_body at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>interpreter<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">799</span>
jl_interpret_toplevel_thunk at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>interpreter<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">911</span>
jl_toplevel_eval_flex at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>toplevel<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">814</span>
jl_toplevel_eval_flex at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>toplevel<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">764</span>
jl_toplevel_eval_in at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>toplevel<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">843</span>
eval at <span class="pl-k">./</span>boot<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">331</span>
eval_user_input at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>usr<span class="pl-k">/</span>share<span class="pl-k">/</span>julia<span class="pl-k">/</span>stdlib<span class="pl-k">/</span>v1.<span class="pl-c1">5</span><span class="pl-k">/</span>REPL<span class="pl-k">/</span>src<span class="pl-k">/</span>REPL<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">107</span>
run_backend at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span><span class="pl-k">.</span>julia<span class="pl-k">/</span>packages<span class="pl-k">/</span>Revise<span class="pl-k">/</span>SefCg<span class="pl-k">/</span>src<span class="pl-k">/</span>Revise<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">1042</span>
<span class="pl-c"><span class="pl-c">#</span>85 at ./task.jl:358</span>
jl_apply at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>julia<span class="pl-k">.</span>h<span class="pl-k">:</span><span class="pl-c1">1694</span> [inlined]
start_task at <span class="pl-k">/</span>home<span class="pl-k">/</span>takafumi<span class="pl-k">/</span>repos<span class="pl-k">/</span>watch<span class="pl-k">/</span>julia<span class="pl-k">/</span>src<span class="pl-k">/</span>task<span class="pl-k">.</span>c<span class="pl-k">:</span><span class="pl-c1">687</span>
unknown <span class="pl-k">function</span> (ip<span class="pl-k">:</span> (nil))
Allocations<span class="pl-k">:</span> <span class="pl-c1">14143307</span> (Pool<span class="pl-k">:</span> <span class="pl-c1">14139964</span>; Big<span class="pl-k">:</span> <span class="pl-c1">3343</span>); GC<span class="pl-k">:</span> <span class="pl-c1">14</span></pre></div>
<p dir="auto">When redefining a variable containing an anonymous function with an anonymous function containing the variable itself, that reference is not expanded properly before the new assignment. Therefore, the new function (now bound to the variable) contains a reference to itself and not the old function.</p>
<p dir="auto">I do think this is erroneous behaviour, since in variable assignment the right side should be expanded fully before being bound to the left, just like <code class="notranslate">a=a+1</code> does not produce infinity.</p>
<p dir="auto">Example</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; f = x -&gt; 2*x
(::#1) (generic function with 1 method)

julia&gt; f = x -&gt; 2*f(x)
(::#3) (generic function with 1 method)

julia&gt; f(2)
ERROR: StackOverflowError:
Stacktrace:
 [1] (::##3#4)(::Int64) at ./REPL[2]:1 (repeats 26667 times)

julia&gt; @code_lowered f(2)
CodeInfo(:(begin 
        nothing
        return 2 * (Main.f)(x)
    end))
"><pre class="notranslate">julia<span class="pl-k">&gt;</span> f <span class="pl-k">=</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">2</span><span class="pl-k">*</span>x
(<span class="pl-k">::</span><span class="pl-c"><span class="pl-c">#</span>1) (generic function with 1 method)</span>

julia<span class="pl-k">&gt;</span> f <span class="pl-k">=</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">2</span><span class="pl-k">*</span><span class="pl-c1">f</span>(x)
(<span class="pl-k">::</span><span class="pl-c"><span class="pl-c">#</span>3) (generic function with 1 method)</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">f</span>(<span class="pl-c1">2</span>)
ERROR<span class="pl-k">:</span> StackOverflowError<span class="pl-k">:</span>
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] (<span class="pl-k">::</span><span class="pl-c"><span class="pl-c">#</span>#3#4)(::Int64) at ./REPL[2]:1 (repeats 26667 times)</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@code_lowered</span> <span class="pl-c1">f</span>(<span class="pl-c1">2</span>)
<span class="pl-c1">CodeInfo</span>(:(<span class="pl-k">begin</span> 
        <span class="pl-c1">nothing</span>
        <span class="pl-k">return</span> <span class="pl-c1">2</span> <span class="pl-k">*</span> (Main<span class="pl-k">.</span>f)(x)
    <span class="pl-k">end</span>))
</pre></div>
<p dir="auto">I do not know where this problem stems from and where it should be fixed.<br>
Apologies if this is a duplicate, I haven't found anything resembling this in the open issues.</p>