Skip to content

Commit

Permalink
go/types, types2: better variable names, cleanups in test
Browse files Browse the repository at this point in the history
For golang#54258.

Change-Id: Ib0d326af2719bca1579f84c125f6573f87dce982
Reviewed-on: https://go-review.googlesource.com/c/go/+/452455
Run-TryBot: Robert Findley <[email protected]>
Auto-Submit: Robert Griesemer <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
Run-TryBot: Robert Griesemer <[email protected]>
  • Loading branch information
griesemer authored and felixge committed Nov 21, 2022
1 parent a8c6f11 commit b44e79d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/cmd/compile/internal/types2/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,18 @@ func (S) M5(struct {S;t}) {}
.*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 {
Expand Down
17 changes: 9 additions & 8 deletions src/go/types/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,18 +833,19 @@ func (S) M5(struct {S;t}) {}
.*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 {
Expand Down
7 changes: 0 additions & 7 deletions src/go/types/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"fmt"
"go/constant"
"go/token"
"unicode"
"unicode/utf8"
)

// An Object describes a named language entity such as a package,
Expand Down Expand Up @@ -59,11 +57,6 @@ type Object interface {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/typestring.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (w *typeWriter) typ(typ Type) {
// 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
Expand Down

0 comments on commit b44e79d

Please sign in to comment.