Skip to content

inconsistent compiler behavior between gc and go/types #9390

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

Closed
zeebo opened this issue Dec 19, 2014 · 4 comments
Closed

inconsistent compiler behavior between gc and go/types #9390

zeebo opened this issue Dec 19, 2014 · 4 comments

Comments

@zeebo
Copy link
Contributor

zeebo commented Dec 19, 2014

Consider this program:

package main

import (
    "fmt"
    "go/ast"
    "go/parser"
    "go/token"

    _ "golang.org/x/tools/go/gcimporter"
    "golang.org/x/tools/go/types"
)

func foo() {
    var x int
    func() {
        x = 1
    }()
}

func main() {
    fset := token.NewFileSet()
    file, err := parser.ParseFile(fset, "./repro.go", nil, 0)
    if err != nil {
        panic(err)
    }

    _, err = types.Check("repro", fset, []*ast.File{file})
    fmt.Println("error:", err)
}

If you place it in $GOPATH/src/repro/repro.go then you can build it with gc (go version 1.4), but if you run it, golang.org/x/tools/go/types (most recent tip at time of issue report) fails to type check.

It seems like they disagree on if x is considered to be used or not.

@ianlancetaylor
Copy link
Contributor

Dup of issue #3059.

@zeebo
Copy link
Contributor Author

zeebo commented Dec 19, 2014

I appreciate that the behavior that gc is doing here is a dupe of #3059 but the more important part in my opinion is that go/types disagrees and considers it an error. It doesn't look like #3059 has that information. Where should that issue be tracked, or is that not an issue because this is implementation defined in the spec?

@ianlancetaylor
Copy link
Contributor

Personally I think go/types is correct and cmd/gc is wrong, so I'm not sure what needs to be tracked.

@zeebo
Copy link
Contributor Author

zeebo commented Dec 19, 2014

I agree. I'll just leave a comment on the other ticket describing the pain I experienced due to this to maybe help prioritize fixing it since it's not obvious how cmd/gc accepting these programs is harmful.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants