I think I've encountered a Go bug, but need verification

polaris · · 459 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Calling <code>(* File)Readdirnames(0)</code> twice should return an empty slice the second time. However, it the docs mention that the error would be non-nil in that case. The err value is always nil on my system (amd64 linux).</p> <p>Is the same for others here?</p> <hr/>**评论:**<br/><br/>barsonme: <pre><pre><code>If n &gt; 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF. </code></pre> <p>It only returns an empty slice <em>and</em> an error if n &gt; 0. In your example, n == 0 so the second case would apply:</p> <pre><code>If n &lt;= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error. </code></pre> <p>...which does not mention nil slices and errors.</p></pre>borring: <pre><p>Thanks for pointing that out. I really need to stop skimming when going through the docs</p></pre>barsonme: <pre><p>happens to all of us :)</p></pre>weberc2: <pre><p>I just want to point out that this conversation would have had a lot more screaming about manual reading in other languages&#39; subreddits. Thanks for keeping it classy, folks. :)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

459 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传