]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: clean up the set up of error, comparable
authorRobert Griesemer <gri@golang.org>
Wed, 26 Jan 2022 21:44:45 +0000 (13:44 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 26 Jan 2022 22:33:26 +0000 (22:33 +0000)
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>
src/cmd/compile/internal/types2/universe.go
src/go/types/universe.go

index c16ae3f63eafd0cc90ec46b6e3a6b94b1ff52cec..6ee5dbdca3505b144d032ad5a4739adfc68bc523 100644 (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)
        }
 }
index edda56fc0dbf174998c970b2d901a394a5e51fbf..34216346789cd8acdcd9e31ae7f874b86dd372ee 100644 (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)
        }
 }