1
0
mirror of https://github.com/golang/go synced 2024-09-23 23:10:13 -06:00

doc.Example should not worry about unresolved blank identifiers

https://golang.org/pkg/bufio/#example_Scanner_custom is not directly
runnable in the playground via godoc, but if I copy+paste the code into
https://play.golang.org/ then it runs just fine.

This seems to be due to the blank identifier being considered unresolved
in the following line in the example:

_, err = strconv.ParseInt(string(token), 10, 32)

But that's the whole point of blank identifiers- they're not supposed
to be resolved.  So let's skip adding the blank identifier to
doc.playExample's unresolved map.

Fixes #26447

Change-Id: I52bc7d99be1d14a61dc012d10c18349d52ba4c51
GitHub-Last-Rev: 9172e9dc13
GitHub-Pull-Request: golang/go#26448
Reviewed-on: https://go-review.googlesource.com/124775
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Mostyn Bramley-Moore 2018-08-08 21:34:43 +00:00 committed by Robert Griesemer
parent 6b937ace68
commit f2131f6e0c

View File

@ -188,7 +188,7 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File {
inspectFunc = func(n ast.Node) bool {
switch e := n.(type) {
case *ast.Ident:
if e.Obj == nil {
if e.Obj == nil && e.Name != "_" {
unresolved[e.Name] = true
} else if d := topDecls[e.Obj]; d != nil {
if !hasDepDecls[d] {