<p dir="auto">This was very surprising to me, and took me a very long time to figure out:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; using Random

julia&gt; rng = Random.GLOBAL_RNG
_GLOBAL_RNG()

julia&gt; deepcopy(rng) === rng
true"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">using</span> Random

julia<span class="pl-k">&gt;</span> rng <span class="pl-k">=</span> Random<span class="pl-k">.</span>GLOBAL_RNG
<span class="pl-c1">_GLOBAL_RNG</span>()

julia<span class="pl-k">&gt;</span> <span class="pl-c1">deepcopy</span>(rng) <span class="pl-k">===</span> rng
<span class="pl-c1">true</span></pre></div>
<p dir="auto">Even more surprising is</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; copy(rng) === rng
false"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">copy</span>(rng) <span class="pl-k">===</span> rng
<span class="pl-c1">false</span></pre></div>
<p dir="auto">There's similar behavior with <code class="notranslate">ENV</code> in place of <code class="notranslate">GLOBAL_RNG</code>.</p>
<p dir="auto">There are a few issues here:</p>
<ol dir="auto">
<li>The behavior of <code class="notranslate">deepcopy</code> on <code class="notranslate">GLOBAL_RNG</code> is very different than for other RNGs. It's not clear that the former should be "special" in this way.</li>
<li>I had always understood <code class="notranslate">deepcopy</code> to be a stronger version of <code class="notranslate">copy</code>, in the sense that <code class="notranslate">copy</code> may still result in shared mutable sub-structures, but that <code class="notranslate">deepcopy</code> would replicate these, so the result of <code class="notranslate">deepcopy</code> would have no mutable substructures in common with the original.</li>
</ol>
<p dir="auto">I had some discussion about this on Zulip with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Seelengrab/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Seelengrab">@Seelengrab</a> and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/fredrikekre/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/fredrikekre">@fredrikekre</a> <a href="https://julialang.zulipchat.com/#narrow/stream/137791-general/topic/deepcopy.28.3A.3ARandom.2EGLOBAL_RNG.29.20doesn't.20copy/near/259893815" rel="nofollow">here</a>. Fredrik pointed out that</p>
<blockquote>
<p dir="auto"><code class="notranslate">deepcopy</code> is really a very different function; it almost belongs in the Serialization package or something of that sort.<br>
(from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1034916173" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/42796" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/42796/hovercard?comment_id=951232853&amp;comment_type=issue_comment" href="https://github.com/JuliaLang/julia/issues/42796#issuecomment-951232853">#42796 (comment)</a>)</p>
</blockquote>
<p dir="auto">If this is really the intent, it seems it ought to be well-documented, with guidance on when to use which one.</p>
<p dir="auto">In any case, I can't imagine a use case for the current arrangement where <code class="notranslate">deepcopy</code> can result in strictly more sharing than <code class="notranslate">copy</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let
  function wat()
    a::String = &quot;wat&quot;
    println(a)
  end

  a::String = &quot;me&quot;
  wat()
end"><pre class="notranslate"><code class="notranslate">let
  function wat()
    a::String = "wat"
    println(a)
  end

  a::String = "me"
  wat()
end
</code></pre></div>
<p dir="auto">This will throw an exception telling me</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR: LoadError: syntax: type of &quot;a&quot; declared in inner scope
while loading /wat.jl, in expression starting on line 1"><pre class="notranslate"><code class="notranslate">ERROR: LoadError: syntax: type of "a" declared in inner scope
while loading /wat.jl, in expression starting on line 1
</code></pre></div>
<p dir="auto">Which is really not helpful at all. Line 1? Wow, thanks! 'syntax: type of "a" declared in inner scope' that tells me nothing, what is wrong with that. It sounds like there are some words missing e. g. " is not allowed because X".</p>
<p dir="auto">Now my real issue here is, why is this not legal? Why can I not have a function with a local variables whos name is equal to one from outside the function?</p>