go/types, types2: clean up the set up of error, comparable

Follow-up on CL 380754.

For #50791.

Change-Id: Ia2f8f9785c2f02647525e7ee4168991fd4066dd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/381094
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2022-01-26 13:44:45 -08:00
parent ca6a5c0d51
commit ef0b09c526
2 changed files with 34 additions and 14 deletions

View File

@ -88,22 +88,32 @@ func defPredeclaredTypes() {
{
obj := NewTypeName(nopos, nil, "error", nil)
obj.setColor(black)
typ := NewNamed(obj, nil, nil)
// error.Error() string
recv := NewVar(nopos, nil, "", typ)
res := NewVar(nopos, nil, "", Typ[String])
sig := NewSignatureType(nil, nil, nil, nil, NewTuple(res), false)
sig := NewSignatureType(recv, nil, nil, nil, NewTuple(res), false)
err := NewFunc(nopos, nil, "Error", sig)
ityp := &Interface{nil, obj, []*Func{err}, nil, nil, false, true, nil}
// interface{ Error() string }
ityp := &Interface{obj: obj, methods: []*Func{err}, complete: true}
computeInterfaceTypeSet(nil, nopos, ityp) // prevent races due to lazy computation of tset
typ := NewNamed(obj, ityp, nil)
sig.recv = NewVar(nopos, nil, "", typ)
typ.SetUnderlying(ityp)
def(obj)
}
// type comparable interface{ /* type set marked comparable */ }
// type comparable interface{} // marked as comparable
{
obj := NewTypeName(nopos, nil, "comparable", nil)
obj.setColor(black)
ityp := &Interface{nil, obj, nil, nil, nil, false, true, &_TypeSet{true, nil, allTermlist}}
NewNamed(obj, ityp, nil)
typ := NewNamed(obj, nil, nil)
// interface{} // marked as comparable
ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{true, nil, allTermlist}}
typ.SetUnderlying(ityp)
def(obj)
}
}

View File

@ -89,22 +89,32 @@ func defPredeclaredTypes() {
{
obj := NewTypeName(token.NoPos, nil, "error", nil)
obj.setColor(black)
typ := NewNamed(obj, nil, nil)
// error.Error() string
recv := NewVar(token.NoPos, nil, "", typ)
res := NewVar(token.NoPos, nil, "", Typ[String])
sig := NewSignatureType(nil, nil, nil, nil, NewTuple(res), false)
sig := NewSignatureType(recv, nil, nil, nil, NewTuple(res), false)
err := NewFunc(token.NoPos, nil, "Error", sig)
ityp := &Interface{nil, obj, []*Func{err}, nil, nil, false, true, nil}
// interface{ Error() string }
ityp := &Interface{obj: obj, methods: []*Func{err}, complete: true}
computeInterfaceTypeSet(nil, token.NoPos, ityp) // prevent races due to lazy computation of tset
typ := NewNamed(obj, ityp, nil)
sig.recv = NewVar(token.NoPos, nil, "", typ)
typ.SetUnderlying(ityp)
def(obj)
}
// type comparable interface{ /* type set marked comparable */ }
// type comparable interface{} // marked as comparable
{
obj := NewTypeName(token.NoPos, nil, "comparable", nil)
obj.setColor(black)
ityp := &Interface{nil, obj, nil, nil, nil, false, true, &_TypeSet{true, nil, allTermlist}}
NewNamed(obj, ityp, nil)
typ := NewNamed(obj, nil, nil)
// interface{} // marked as comparable
ityp := &Interface{obj: obj, complete: true, tset: &_TypeSet{true, nil, allTermlist}}
typ.SetUnderlying(ityp)
def(obj)
}
}