diff options
author | Robert Griesemer <gri@golang.org> | 2022-01-26 13:44:45 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-01-26 22:33:26 +0000 |
commit | ef0b09c526d78de23186522d50ff93ad657014c0 (patch) | |
tree | 4443458bb3ded32302230c7887f05427fee4e9d5 | |
parent | ca6a5c0d518463b40c3e6e56655d45d9fd60e1f7 (diff) | |
download | go-ef0b09c526d78de23186522d50ff93ad657014c0.tar.gz go-ef0b09c526d78de23186522d50ff93ad657014c0.zip |
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>
-rw-r--r-- | src/cmd/compile/internal/types2/universe.go | 24 | ||||
-rw-r--r-- | src/go/types/universe.go | 24 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/cmd/compile/internal/types2/universe.go b/src/cmd/compile/internal/types2/universe.go index c16ae3f63e..6ee5dbdca3 100644 --- a/src/cmd/compile/internal/types2/universe.go +++ b/src/cmd/compile/internal/types2/universe.go @@ -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) } } diff --git a/src/go/types/universe.go b/src/go/types/universe.go index edda56fc0d..3421634678 100644 --- a/src/go/types/universe.go +++ b/src/go/types/universe.go @@ -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) } } |