diff options
Diffstat (limited to 'tools/go_generics/generics.go')
-rw-r--r-- | tools/go_generics/generics.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/go_generics/generics.go b/tools/go_generics/generics.go index 4e5cc53a2..e9cc2c753 100644 --- a/tools/go_generics/generics.go +++ b/tools/go_generics/generics.go @@ -82,7 +82,12 @@ // Note that the second call to g() kept "b" as an argument because it refers to // the local variable "b". // -// Unfortunately, go_generics does not handle anonymous fields with renamed types. +// Note that go_generics can handle anonymous fields with renamed types if +// -anon is passed in, however 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. +// +// You can see an example in the tools/go_generics/generics_tests/interface test. package main import ( @@ -108,6 +113,7 @@ var ( prefix = flag.String("prefix", "", "`prefix` to add to each global symbol") packageName = flag.String("p", "main", "output package `name`") printAST = flag.Bool("ast", false, "prints the AST") + processAnon = flag.Bool("anon", false, "process anonymous fields") types = make(mapValue) consts = make(mapValue) imports = make(mapValue) @@ -222,12 +228,16 @@ func main() { // Modify the state tag appropriately. if m := stateTagRegexp.FindStringSubmatch(ident.Name); m != nil { if t := identifierRegexp.FindStringSubmatch(m[2]); t != nil { - ident.Name = m[1] + `state:".(` + t[1] + *prefix + t[2] + *suffix + t[3] + `)"` + m[3] + typeName := *prefix + t[2] + *suffix + if n, ok := types[t[2]]; ok { + typeName = n + } + ident.Name = m[1] + `state:".(` + t[1] + typeName + t[3] + `)"` + m[3] } } } } - }) + }, *processAnon) // Remove the definition of all types that are being remapped. set := make(typeSet) |