On Saturday, October 1, 2016 at 11:50:24 PM UTC+8, Nate Finch wrote: > > There are a couple details to how go/types.Type values compare that I > think need better documentation. Ideally there would be some programmatic > improvement, but that might not be possible. > > First: go/types.Type as map keys work... Someof the time. The built-in > Types under types.Typ work. Other values, like ones constructed with > types.NewPointer, apparently never hash the same, even if they are > logically the same type. The compiler doesn't complain about unhashable > values, though. > > Second: types created from two different loaders ( > golang.org/x/tools/go/loader) never return true from types.Identical even > if they were constructed the exact same way (like comparing the type of the > first argument of encoding/json.Indent). > > Put together, these two facts made my first experience with go/types very > frustrating. Basically the whole point of the package for anything other > than simple type checking, is to compare types. > > It would be nice if these two things were documented, and ideally, if they > could be fixed (preventing typed from being used as map keys, or making > them function sanely, and making the same type from two loaders > types.Identical = true) >
For the first, it is well explained here: https://github.com/golang/example/tree/master/gotypes#types You should use "Identical" function to compare two types. -- 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. For more options, visit https://groups.google.com/d/optout.