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
image: broken example #4300
Labels
Milestone
Comments
Labels changed: added priority-soon, documentation, removed priority-triage. Owner changed to @robpike. Status changed to Accepted. |
godoc -play -http :6060 then goto http://localhost:6060/pkg/image click Example, the example shown is lacking the blank id. import of "image/jpeg". https://golang.org/cl/6813061/ is created to fix that. After that CL, we can change that example to use absolute path for data files, and then that example should be able to at least run locally. btw, can we change cmd/godoc/play-local.go to run the requested file locally instead of bouncing to play.golang.org? i think it can enable a new way of learning Go standard packages. |
I don't know yet why the formatting is off - need to investigate. That said, the patch https://golang.org/cl/6813061/ has other issues as well. When running godoc -play -http :6060 as suggested, _and_ with image/decode_example_test.go modified such that the import section looks like this: import ( "fmt" "image" "log" "os" // Package image/jpeg is not used explicitly in the code below, // but is imported for its initialization side-effect, which allows // image.Decode to understand JPEG formatted images. Uncomment these // two lines to also understand GIF and PNG images: // _ "image/gif" _ "image/png" _ "image/jpeg" ) (two last imports enabled but one), I get a crash: 2012/11/02 16:45:05 http: panic serving [::1]:49365: runtime error: invalid memory address or nil pointer dereference $GOROOT/src/pkg/net/http/server.go:601 (0x873c6) func.004: buf.Write(debug.Stack()) $GOROOT/src/pkg/runtime/panic.c:134 (0x3afb6) panic: reflect·call(d->fn, (byte*)d->args, d->siz); $GOROOT/src/pkg/runtime/panic.c:384 (0x3b6a3) panicstring: runtime·panic(err); $GOROOT/src/pkg/runtime/thread_darwin.c:427 (0x42408) sigpanic: runtime·panicstring("invalid memory address or nil pointer dereference"); $GOROOT/src/pkg/go/ast/ast.go:77 (0x10e2ac) (*CommentGroup).Pos: func (g *CommentGroup) Pos() token.Pos { return g.List[0].Pos() } $GOROOT/src/pkg/go/doc/example.go:184 (0xc6c5f) playExample: if c.Pos() >= p.Doc.Pos() && c.Pos() < p.Doc.End() { $GOROOT/src/pkg/go/doc/example.go:62 (0xc612d) Examples: Play: playExample(file, f.Body), $GOROOT/src/cmd/godoc/godoc.go:977 (0x12551) (*docServer).getPageInfo: examples = append(examples, doc.Examples(files...)...) $GOROOT/src/cmd/godoc/godoc.go:1050 (0x12bf8) (*docServer).ServeHTTP: info := h.getPageInfo(abspath, relpath, mode) $GOROOT/src/pkg/net/http/server.go:988 (0x7d831) (*ServeMux).ServeHTTP: h.ServeHTTP(w, r) $GOROOT/src/cmd/godoc/main.go:96 (0x26983) func.016: h.ServeHTTP(w, req) $GOROOT/src/pkg/net/http/server.go:729 (0x7c6ab) HandlerFunc.ServeHTTP: f(w, r) $GOROOT/src/pkg/net/http/server.go:681 (0x7c35d) (*conn).serve: handler.ServeHTTP(w, w.req) $GOROOT/src/pkg/runtime/proc.c:277 (0x3cb60) goexit: runtime·goexit(void) Owner changed to @griesemer. Status changed to Accepted. |
The reason for the misalignment is due to the change of filename in the position information of the created example: Because the created example is made up from nodes from different files (and nodes that have no position information), the printer sees various transitions of file names in the position information. For instance, when printing the imports, it sees the following file name transitions (in the [] boxes): import [->/src/pkg/image/format.go](>>> "fmt" "image" "log" "os" [/src/pkg/image/format.go->/src/pkg/image/decode_example_test.go]// Package image/jpeg is not used explicitly in the code below, // but is imported for its initialization side-effect, which allows // image.Decode to understand JPEG formatted images. Uncomment these // two lines to also understand GIF and PNG images: // _ "image/gif" // _ "image/png" _ "image/jpeg"<<< [/src/pkg/image/decode_example_test.go->/src/pkg/image/format.go]) (The >>> and <<< markers show increases/decreases of indentation). At the moment, each time the file name changes in the position information, the printer assumes that the formatting state should be reset - basically it assumes that we are not building ASTs that contain pieces of different files within a single declaration. However this is the case here. When the formatting state is reset, the indentation goes to zero; hence the misalignment. In fact, before the end of the import declaration, the indentation goes to -1, and in debug mode (go/printer/printer.go:22 debug = true) we get a respective panic. The offensive line is go/printer/printer.go:228 p.indent = 0. Commenting that line out will resolve the issue. See: http://golang.org/cl/6849066 . |
This issue was closed by revision 80dcc43. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by darkgray:
The text was updated successfully, but these errors were encountered: