For #54258.
Change-Id: Ib0d326af2719bca1579f84c125f6573f87dce982
Reviewed-on: https://go-review.googlesource.com/c/go/+/452455
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
.*want M5[(]struct{b[.]S; t}[)]`},
}
- test := func(main, imported, want string) {
+ test := func(main, b, want string) {
re := regexp.MustCompile(want)
- a := mustTypecheck("b", imported, nil)
- bast := mustParse("", main)
- conf := Config{Importer: importHelper{pkg: a}}
- _, err := conf.Check(bast.PkgName.Value, []*syntax.File{bast}, nil)
+ bpkg := mustTypecheck("b", b, nil)
+ mast := mustParse("main.go", main)
+ conf := Config{Importer: importHelper{pkg: bpkg}}
+ _, err := conf.Check(mast.PkgName.Value, []*syntax.File{mast}, nil)
if err == nil {
- t.Errorf("Expected failure, but it did not")
+ t.Error("Expected failure, but it did not")
} else if got := err.Error(); !re.MatchString(got) {
- t.Errorf("Wanted match for\n%s\n but got \n%s", want, got)
+ t.Errorf("Wanted match for\n\t%s\n but got\n\t%s", want, got)
} else if testing.Verbose() {
- t.Logf("Saw expected\n%s", err.Error())
+ t.Logf("Saw expected\n\t%s", err.Error())
}
}
for _, t := range tests {
.*want M5[(]struct{b[.]S; t}[)]`},
}
- test := func(main, imported, want string) {
+ fset := token.NewFileSet()
+ test := func(main, b, want string) {
re := regexp.MustCompile(want)
- a := mustTypecheck("b", imported, nil)
- bast := mustParse(fset, "", main)
- conf := Config{Importer: importHelper{pkg: a}}
- _, err := conf.Check(bast.Name.Name, fset, []*ast.File{bast}, nil)
+ bpkg := mustTypecheck("b", b, nil)
+ mast := mustParse(fset, "main.go", main)
+ conf := Config{Importer: importHelper{pkg: bpkg}}
+ _, err := conf.Check(mast.Name.Name, fset, []*ast.File{mast}, nil)
if err == nil {
- t.Errorf("Expected failure, but it did not")
+ t.Error("Expected failure, but it did not")
} else if got := err.Error(); !re.MatchString(got) {
- t.Errorf("Wanted match for\n%s\n but got \n%s", want, got)
+ t.Errorf("Wanted match for\n\t%s\n but got\n\t%s", want, got)
} else if testing.Verbose() {
- t.Logf("Saw expected\n%s", err.Error())
+ t.Logf("Saw expected\n\t%s", err.Error())
}
}
for _, t := range tests {
"fmt"
"go/constant"
"go/token"
- "unicode"
- "unicode/utf8"
)
// An Object describes a named language entity such as a package,
setScopePos(pos token.Pos)
}
-func isExported(name string) bool {
- ch, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(ch)
-}
-
// Id returns name if it is exported, otherwise it
// returns the name qualified with the package path.
func Id(pkg *Package, name string) string {
// If disambiguating one struct for another, look for the first unexported field.
// Do this first in case of nested structs; tag the first-outermost field.
pkgAnnotate := false
- if w.qf == nil && w.pkgInfo && !isExported(f.name) {
+ if w.qf == nil && w.pkgInfo && !token.IsExported(f.name) {
// note for embedded types, type name is field name, and "string" etc are lower case hence unexported.
pkgAnnotate = true
w.pkgInfo = false // only tag once