]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: better variable names, cleanups in test
authorRobert Griesemer <gri@golang.org>
Mon, 21 Nov 2022 18:37:37 +0000 (10:37 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 21 Nov 2022 18:58:33 +0000 (18:58 +0000)
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>

src/cmd/compile/internal/types2/issues_test.go
src/go/types/issues_test.go
src/go/types/object.go
src/go/types/typestring.go

index 4d0dcfd672d88b9577877c85468fb0e29866dd01..52784207d7d9acf8467f274174d529affbc82722 100644 (file)
@@ -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 {
index debe3216d4e1135b0d77533abfc8f31c4d14512f..b4845b1def67a10320b812303430408f759df61d 100644 (file)
@@ -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 {
index f5f485999982ec1a8156bfec88b3b9ac88c1163b..6e63948680b12533b2500f37ff4ccac6ab927701 100644 (file)
@@ -9,8 +9,6 @@ import (
        "fmt"
        "go/constant"
        "go/token"
-       "unicode"
-       "unicode/utf8"
 )
 
 // An Object describes a named language entity such as a package,
@@ -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 {
index 33251d779c2af95d5d4d15636884f2a45616b976..cfeb7eb404300d7f409d110eb4e34caaa63b2325 100644 (file)
@@ -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