<p dir="auto">The following program, <a href="http://play.golang.org/p/92JZyQQ-Gr" rel="nofollow">http://play.golang.org/p/92JZyQQ-Gr</a>, fails because an <code class="notranslate">err</code> value is shadowed.</p>
<p dir="auto">This error cropped up a few times in the standard library (and more times in user code).</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/robpike/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/robpike">@robpike</a> thinks the compiler should catch this.</p>
<p dir="auto">Discussion: <a href="https://groups.google.com/forum/#!topic/golang-nuts/MdDLbvOjb4o" rel="nofollow">https://groups.google.com/forum/#!topic/golang-nuts/MdDLbvOjb4o</a></p>
<p dir="auto">This block<br>
{<br>
x := 0<br>
_ = x<br>
x = 1<br>
}<br>
compiles without error, whereas I would expect an error on the "x=1" line.  Something like "x assigned and not used".</p>
<p dir="auto">For precedent we have the existing "x declared and not used" error.  This is essentially the same error.</p>
<p dir="auto">For someone bitten by the lack of this error, see <a href="http://www.qureet.com/blog/golang-beartrap/" rel="nofollow">http://www.qureet.com/blog/golang-beartrap/</a></p>