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/types: ExampleMethodSet errors, but doesn't fail #15261

Closed
jmank88 opened this issue Apr 12, 2016 · 3 comments
Closed

go/types: ExampleMethodSet errors, but doesn't fail #15261

jmank88 opened this issue Apr 12, 2016 · 3 comments

Comments

@jmank88
Copy link

@jmank88 jmank88 commented Apr 12, 2016

  1. What version of Go are you using (go version)?
    Whatever golang.org is using behind the scenes to run examples, as of 2016-4-12 ~5pm CT.

  2. What operating system and processor architecture are you using (go env)?
    Same as 1.

  3. What did you do?
    Ran the example code here: https://golang.org/pkg/go/types/#example_MethodSet

  4. What did you expect to see?
    I expected the program to "Print the method sets of Celsius and *Celsius." as documented.

  5. What did you see instead?
    An error:

    2009/11/10 23:00:00 celsius.go:3:8: could not import fmt (can't find import: )

The error is returned from this call:

pkg, err := conf.Check("temperature", fset, []*ast.File{f}, nil)

Since this example does not specify its expected output (// Output:), this failure will not be registered via go test. Edit: the source files have // Output:, so it's not clear to me what is happening.

I'm new to go/types, so it's not clear to me whether the example is broken, or packages are broken.

@jmank88 jmank88 changed the title go/types ExampleMethodSet failing go/types ExampleMethodSet errors, but doesn't fail Apr 12, 2016
@jmank88
Copy link
Author

@jmank88 jmank88 commented Apr 12, 2016

The same problem affects ExampleScope as well.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Apr 12, 2016

@jmank88 go/types requires the "fmt" package to be installed. This code runs fine if you copy it and run it locally (with a std library installed), or if you run the godoc server locally (with a std library installed). go/types and the example are correct but the example set up may need tweaks, or perhaps an explanation. Leaving for @alandonovan who added this example.

Loading

@ianlancetaylor ianlancetaylor changed the title go/types ExampleMethodSet errors, but doesn't fail go/types: ExampleMethodSet errors, but doesn't fail Apr 12, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Apr 12, 2016
@alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Apr 18, 2016

As the comment in the example says, the importer loads files from $GOROOT/pkg/$GOOS_$GOOARCH/fmt.a; these files are not present in the Playground's sandbox.

Not all example programs are intended to be executable in the Go Playground, for example, anything that accesses the network will not work. This is a limitation of the Playground, not a mistake in the example.

Loading

@golang golang locked and limited conversation to collaborators Apr 18, 2017
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