Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/ast: CommentMap example does not compile #20450

Closed
ritesh opened this issue May 22, 2017 · 5 comments
Closed

go/ast: CommentMap example does not compile #20450

ritesh opened this issue May 22, 2017 · 5 comments

Comments

@ritesh
Copy link

@ritesh ritesh commented May 22, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ritesh/code/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/5x/m5n_f_wj6fngljvf9g7y3mp4qphpn9/T/go-build111820297=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Tried to run the example in https://golang.org/pkg/go/ast/#example_CommentMap. A link to the full program, with imports, is here:
https://play.golang.org/p/5DA91qtnm4

What did you expect to see?

Expected the example to run, without any errors.

What did you see instead?

tmp/sandbox659516205/main.go:44: undefined: removeFirstVarDecl

@ALTree
Copy link
Member

@ALTree ALTree commented May 22, 2017

The example is not rendered as a runnable example (we have examples that cannot be run in the playground, for example the ones that need access to the filesystem, and we render them without the run button) so IMHO you shouldn't expect it to actually be runnable.

The purpose of the example is to show how to use CommentMap and you can treat removeFirstVarDecl as a black box (that does what it says in the name) while reading the example's code.

@ALTree ALTree changed the title AST CommentMap example does not compile go/ast: CommentMap example does not compile May 22, 2017
@ritesh
Copy link
Author

@ritesh ritesh commented May 22, 2017

Thanks for the quick response!
That's a fair point. However, I think there's some value in making this particular example close to runnable/runnable especially for a concept that's difficult to grasp for beginners like me. Adding in the imports and removing the call to removeFirstValDecl is all that's needed to get it to run.

@josharian
Copy link
Contributor

@josharian josharian commented May 23, 2017

If we can make it runnable without losing clarity, I think we should do it.

@josharian josharian added this to the Go1.10 milestone May 23, 2017
@codyoss
Copy link
Member

@codyoss codyoss commented Jul 15, 2017

I would like to claim this issue.

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 15, 2017

CL https://golang.org/cl/48969 mentions this issue.

@gopherbot gopherbot closed this in 91afca9 Jul 16, 2017
@golang golang locked and limited conversation to collaborators Jul 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.