Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (28 sloc) 653 Bytes
package main
import (
"go/ast"
"go/types"
"golang.org/x/tools/go/loader"
)
// walkForType walks the AST tree and returns the type of the expression
func walkForType(pkgInfo *loader.PackageInfo, node ast.Node) types.Type {
var result types.Type
visit := func(node ast.Node) bool {
if expr, ok := node.(ast.Expr); ok {
if typeAndValue, ok := pkgInfo.Types[expr]; ok {
result = typeAndValue.Type
return false
}
}
return true
}
ast.Inspect(node, visit)
return result
}
func isUnknownType(typ types.Type) bool {
if typ == nil {
return true
}
basic, ok := typ.(*types.Basic)
return ok && basic.Kind() == types.Invalid
}
You can’t perform that action at this time.