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/doc: examples that depend on top-level functions should be playable #23095

Closed
hirochachacha opened this issue Dec 12, 2017 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hirochachacha
Copy link
Contributor

See https://golang.org/pkg/go/types/#example_Info
The example isn't runnable because two functions
func mode(tv types.TypeAndValue) string and func exprString(fset *token.FileSet, expr ast.Expr) string
are declared outside of func ExampleInfo().
Ideally, tools should consult this situation.

@dsnet
Copy link
Member

dsnet commented Dec 12, 2017

Ideally, tools should consult this situation.

I'm not sure I understand what you mean by this.

@hirochachacha
Copy link
Contributor Author

I'm not sure how godoc works, but I suppose

package xxx

import "fmt"

func b() {
  fmt.Println("B")
}

func ExampleA() {
  fmt.Println("A")
}

func ExampleB() {
  b()
}

godoc can construct complete program for A.

package main

import "fmt"

func main() {
  fmt.Println("A")
}

But, it cannot construct complete program for B. It should emit

package main

import "fmt"

func b() {
  fmt.Println("B")
}

func main() {
  b()
}

I guess?

@gopherbot
Copy link

Change https://golang.org/cl/83615 mentions this issue: go/doc: make examples that depends on top-level decl playable

@hirochachacha hirochachacha changed the title doc: show dependent declarations go/doc: examples that depend on top-level functions should be playable Dec 13, 2017
@ianlancetaylor ianlancetaylor added NeedsFix The path to resolution is known, but the work has not been done. and removed Documentation labels Mar 29, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018
@golang golang locked and limited conversation to collaborators Jun 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants