From 239d7c6fdf344fe7051328056b7578657c7b6950 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Thu, 4 Jul 2019 08:33:00 +0200 Subject: go_generics: treat the Sel part of an ast.SelectorExpr --- tools/go_generics/globals/globals_visitor.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tools/go_generics/globals/globals_visitor.go') diff --git a/tools/go_generics/globals/globals_visitor.go b/tools/go_generics/globals/globals_visitor.go index 3f948637b..883f21ebe 100644 --- a/tools/go_generics/globals/globals_visitor.go +++ b/tools/go_generics/globals/globals_visitor.go @@ -47,6 +47,11 @@ type globalsVisitor struct { // scope is the current scope as nodes are visited. scope *scope + + // processAnon indicates whether we should process anonymous struct fields. + // It does not perform strict checking on parameter types that share the same name + // as the global type and therefore will rename them as well. + processAnon bool } // unexpected is called when an unexpected node appears in the AST. It dumps @@ -307,6 +312,9 @@ func (v *globalsVisitor) visitExpr(ge ast.Expr) { case *ast.SelectorExpr: v.visitExpr(e.X) + if v.processAnon { + v.visitExpr(e.Sel) + } case *ast.SliceExpr: v.visitExpr(e.X) @@ -577,11 +585,12 @@ func (v *globalsVisitor) visit() { // // The function f() is allowed to modify the identifier, for example, to rename // uses of global references. -func Visit(fset *token.FileSet, file *ast.File, f func(*ast.Ident, SymKind)) { +func Visit(fset *token.FileSet, file *ast.File, f func(*ast.Ident, SymKind), processAnon bool) { v := globalsVisitor{ - fset: fset, - file: file, - f: f, + fset: fset, + file: file, + f: f, + processAnon: processAnon, } v.visit() -- cgit v1.2.3