diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
commit | a16e30d162c1c7408db7821e7b9513cefa09c6ca (patch) | |
tree | af752ba9ba44c547df39bb0af9bff79f610ba9d5 /src/cmd/api/goapi.go | |
parent | 91e4d2d57bc341dd82c98247117114c851380aef (diff) | |
parent | cf6cfba4d5358404dd890f6025e573a4b2156543 (diff) | |
download | go-git-dev.link.tar.gz |
[dev.link] all: merge branch 'master' into dev.linkdev.link
Clean merge.
Change-Id: Ia7b2808bc649790198d34c226a61d9e569084dc5
Diffstat (limited to 'src/cmd/api/goapi.go')
-rw-r--r-- | src/cmd/api/goapi.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 6a80ed269b..b14d57c236 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -326,6 +326,18 @@ func compareAPI(w io.Writer, features, required, optional, exception []string, a return } +// aliasReplacer applies type aliases to earlier API files, +// to avoid misleading negative results. +// This makes all the references to os.FileInfo in go1.txt +// be read as if they said fs.FileInfo, since os.FileInfo is now an alias. +// If there are many of these, we could do a more general solution, +// but for now the replacer is fine. +var aliasReplacer = strings.NewReplacer( + "os.FileInfo", "fs.FileInfo", + "os.FileMode", "fs.FileMode", + "os.PathError", "fs.PathError", +) + func fileFeatures(filename string) []string { if filename == "" { return nil @@ -334,7 +346,9 @@ func fileFeatures(filename string) []string { if err != nil { log.Fatalf("Error reading file %s: %v", filename, err) } - lines := strings.Split(string(bs), "\n") + s := string(bs) + s = aliasReplacer.Replace(s) + lines := strings.Split(s, "\n") var nonblank []string for _, line := range lines { line = strings.TrimSpace(line) @@ -856,6 +870,10 @@ func (w *Walker) emitObj(obj types.Object) { func (w *Walker) emitType(obj *types.TypeName) { name := obj.Name() typ := obj.Type() + if obj.IsAlias() { + w.emitf("type %s = %s", name, w.typeString(typ)) + return + } switch typ := typ.Underlying().(type) { case *types.Struct: w.emitStructType(name, typ) |