Skip to content

inconsistent compiler behavior between gc and go/types #9390

Closed
@zeebo

Description

@zeebo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions