I'm trying to determine if two types are identical with 
`go/types.Identical`, and surprisingly enough, types of the same piece of 
code returned by different `packages.Load` calls are always different.

Am I making a wrong assumption about those APIs?

package main

import (
    "fmt"
    "go/types"

    "golang.org/x/tools/go/packages"
)

func getTimeTime() *types.Named {
    pkgs, err := packages.Load(&packages.Config{
        Mode: packages.NeedImports | packages.NeedSyntax | 
packages.NeedTypes | packages.NeedDeps | packages.NeedTypesInfo,
        Overlay: map[string][]byte{
            "/t1.go": []byte(`package t
            import "time"
            var x time.Time`),
        },
    }, "file=/t1.go")
    if err != nil {
        panic(err)
    }
    for _, v := range pkgs[0].TypesInfo.Types {
        return v.Type.(*types.Named) // named type of time.Time
    }
    panic("unreachable")
}

func main() {
    t1, t2 := getTimeTime(), getTimeTime()
    if !types.Identical(t1, t2) {
        fmt.Println(t1, t2, "are different")
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ab94755e-6444-491a-99a6-fdffe899baa7n%40googlegroups.com.

Reply via email to