...

Source file src/gotest.tools/v3/assert/cmd/gty-migrate-from-testify/walktype.go

Documentation: gotest.tools/v3/assert/cmd/gty-migrate-from-testify

     1  package main
     2  
     3  import (
     4  	"go/ast"
     5  	"go/types"
     6  )
     7  
     8  // walkForType walks the AST tree and returns the type of the expression
     9  func walkForType(pkgInfo *types.Info, node ast.Node) types.Type {
    10  	var result types.Type
    11  
    12  	visit := func(node ast.Node) bool {
    13  		if expr, ok := node.(ast.Expr); ok {
    14  			if typeAndValue, ok := pkgInfo.Types[expr]; ok {
    15  				result = typeAndValue.Type
    16  				return false
    17  			}
    18  		}
    19  		return true
    20  	}
    21  	ast.Inspect(node, visit)
    22  	return result
    23  }
    24  
    25  func isUnknownType(typ types.Type) bool {
    26  	if typ == nil {
    27  		return true
    28  	}
    29  	basic, ok := typ.(*types.Basic)
    30  	return ok && basic.Kind() == types.Invalid
    31  }
    32  

View as plain text