aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/object.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2020-10-22 15:32:05 -0700
committerRobert Griesemer <gri@golang.org>2020-10-27 03:37:05 +0000
commit87eab74628bc23831bd783806e8ec16927bd9a50 (patch)
treeadac6d1cd51a2d77dbc10926b5be0894c2a4dfd2 /src/cmd/compile/internal/types2/object.go
parent5bfd2964a6519c8046b16b41bb9f84ecb6202356 (diff)
downloadgo-87eab74628bc23831bd783806e8ec16927bd9a50.tar.gz
go-87eab74628bc23831bd783806e8ec16927bd9a50.zip
[dev.typeparams] cmd/compile: enable type-checking of generic code
This change makes a first connection between the compiler and types2. When the -G flag is provided, the compiler accepts code using type parameters; with this change generic code is also type-checked (but then compilation ends). Change-Id: I0fa6f6213267a458a6b33afe8ff26869fd838a63 Reviewed-on: https://go-review.googlesource.com/c/go/+/264303 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/object.go')
-rw-r--r--src/cmd/compile/internal/types2/object.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types2/object.go b/src/cmd/compile/internal/types2/object.go
index 6e6f48c036..42fae762d3 100644
--- a/src/cmd/compile/internal/types2/object.go
+++ b/src/cmd/compile/internal/types2/object.go
@@ -10,7 +10,8 @@ import (
"cmd/compile/internal/syntax"
"fmt"
"go/constant"
- "go/token"
+ "unicode"
+ "unicode/utf8"
)
// An Object describes a named language entity such as a package,
@@ -60,10 +61,15 @@ type Object interface {
setScopePos(pos syntax.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 token.IsExported(name) {
+ if isExported(name) {
return name
}
// unexported names need the package path for differentiation
@@ -143,7 +149,7 @@ func (obj *object) Type() Type { return obj.typ }
// Exported reports whether the object is exported (starts with a capital letter).
// It doesn't take into account whether the object is in a local (function) scope
// or not.
-func (obj *object) Exported() bool { return token.IsExported(obj.name) }
+func (obj *object) Exported() bool { return isExported(obj.name) }
// Id is a wrapper for Id(obj.Pkg(), obj.Name()).
func (obj *object) Id() string { return Id(obj.pkg, obj.name) }