mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typealias] go/types: export TypeName.IsAlias so clients can use it
For #18130. Change-Id: I634eaaeaa11e92fc31219d70419fdb4a7aa6e0b4 Reviewed-on: https://go-review.googlesource.com/35099 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
aa1f0681bc
commit
5ceec42dc0
3 changed files with 6 additions and 6 deletions
|
|
@ -163,7 +163,7 @@ func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeName {
|
||||||
return &TypeName{object{nil, pos, pkg, name, typ, 0, token.NoPos}}
|
return &TypeName{object{nil, pos, pkg, name, typ, 0, token.NoPos}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *TypeName) isAlias() bool {
|
func (obj *TypeName) IsAlias() bool {
|
||||||
switch t := obj.typ.(type) {
|
switch t := obj.typ.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return false
|
return false
|
||||||
|
|
@ -330,11 +330,11 @@ func writeObject(buf *bytes.Buffer, obj Object, qf Qualifier) {
|
||||||
if tname != nil {
|
if tname != nil {
|
||||||
// We have a type object: Don't print anything more for
|
// We have a type object: Don't print anything more for
|
||||||
// basic types since there's no more information (names
|
// basic types since there's no more information (names
|
||||||
// are the same; see also comment in TypeName.isAlias).
|
// are the same; see also comment in TypeName.IsAlias).
|
||||||
if _, ok := typ.(*Basic); ok {
|
if _, ok := typ.(*Basic); ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tname.isAlias() {
|
if tname.IsAlias() {
|
||||||
buf.WriteString(" =")
|
buf.WriteString(" =")
|
||||||
} else {
|
} else {
|
||||||
typ = typ.Underlying()
|
typ = typ.Underlying()
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import "testing"
|
||||||
|
|
||||||
func TestIsAlias(t *testing.T) {
|
func TestIsAlias(t *testing.T) {
|
||||||
check := func(obj *TypeName, want bool) {
|
check := func(obj *TypeName, want bool) {
|
||||||
if got := obj.isAlias(); got != want {
|
if got := obj.IsAlias(); got != want {
|
||||||
t.Errorf("%v: got isAlias = %v; want %v", obj, got, want)
|
t.Errorf("%v: got IsAlias = %v; want %v", obj, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
|
||||||
case *Basic:
|
case *Basic:
|
||||||
// Basic types are singletons except for the rune and byte
|
// Basic types are singletons except for the rune and byte
|
||||||
// aliases, thus we cannot solely rely on the x == y check
|
// aliases, thus we cannot solely rely on the x == y check
|
||||||
// above. See also comment in TypeName.isAlias.
|
// above. See also comment in TypeName.IsAlias.
|
||||||
if y, ok := y.(*Basic); ok {
|
if y, ok := y.(*Basic); ok {
|
||||||
return x.kind == y.kind
|
return x.kind == y.kind
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue