diff options
| -rw-r--r-- | gocapturedrefrace.go | 42 | 
1 files changed, 42 insertions, 0 deletions
| diff --git a/gocapturedrefrace.go b/gocapturedrefrace.go index ff5ac9a..d5eaac7 100644 --- a/gocapturedrefrace.go +++ b/gocapturedrefrace.go @@ -20,7 +20,9 @@  package gocapturedrefrace  import ( +	"fmt"  	"go/ast" +	"go/token"  	"go/types"  	"golang.org/x/tools/go/analysis" @@ -85,6 +87,8 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {  	ast.Inspect(  		funcLit,  		func(node ast.Node) bool { +			checkShadowing(pass, node, funcScope) +  			ident, ok := node.(*ast.Ident)  			if !ok {  				return true @@ -108,6 +112,8 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {  				return true  			} +			// fmt.Printf("variable: %#v\n", variable) +  			// Ignore captured callable variables, like function arguments.  			_, isVariableTypeSignature := variable.Type().(*types.Signature)  			if isVariableTypeSignature { @@ -129,3 +135,39 @@ func checkClosure(pass *analysis.Pass, funcLit *ast.FuncLit) {  		},  	)  } + +// TODO: doc +func checkShadowing( +	pass *analysis.Pass, +	node ast.Node, +	funcScope *types.Scope, +) { +	assignStmt, ok := node.(*ast.AssignStmt) +	if !ok { +		return +	} + +	if assignStmt.Tok != token.DEFINE { +		return +	} + +	for _, lhs := range assignStmt.Lhs { +		ident, ok := lhs.(*ast.Ident) +		if !ok { +			return +		} +		fmt.Printf("assignStmt: %#v\n", ident) + +		if ident != nil { +			return +		} + +		// TODO: If ident is in parent, ignore it an move on. +		// scope, scopeObj := funcScope.LookupParent(ident.Name, ident.NamePos) +        // +		// // Identifier is local to the closure. +		// if scope == nil && scopeObj == nil { +		// 	return +		// } +	} +} | 
