From: Robert Griesemer Date: Wed, 26 Jan 2022 21:44:45 +0000 (-0800) Subject: go/types, types2: clean up the set up of error, comparable X-Git-Tag: go1.18beta2~20 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ef0b09c526d78de23186522d50ff93ad657014c0;p=gostls13.git 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 Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Robert Findley --- 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) } }