3 // Type represents value types within the type system.
5 // This is a closed interface type, meaning that only the concrete
6 // implementations provided within this package are considered valid.
11 type typeImpl interface {
12 // isTypeImpl is a do-nothing method that exists only to express
13 // that a type is an implementation of typeImpl.
14 isTypeImpl() typeImplSigil
16 // Equals returns true if the other given Type exactly equals the
18 Equals(other Type) bool
20 // FriendlyName returns a human-friendly *English* name for the given
24 // GoString implements the GoStringer interface from package fmt.
28 // Base implementation of Type to embed into concrete implementations
29 // to signal that they are implementations of Type.
30 type typeImplSigil struct{}
32 func (t typeImplSigil) isTypeImpl() typeImplSigil {
33 return typeImplSigil{}
36 // Equals returns true if the other given Type exactly equals the receiver
38 func (t Type) Equals(other Type) bool {
39 return t.typeImpl.Equals(other)
42 // FriendlyName returns a human-friendly *English* name for the given type.
43 func (t Type) FriendlyName() string {
44 return t.typeImpl.FriendlyName()
47 // GoString returns a string approximating how the receiver type would be
48 // expressed in Go source code.
49 func (t Type) GoString() string {
50 if t.typeImpl == nil {
54 return t.typeImpl.GoString()
57 // NilType is an invalid type used when a function is returning an error
58 // and has no useful type to return. It should not be used and any methods
59 // called on it will panic.
62 // HasDynamicTypes returns true either if the receiver is itself
63 // DynamicPseudoType or if it is a compound type whose descendent elements
64 // are DynamicPseudoType.
65 func (t Type) HasDynamicTypes() bool {
67 case t == DynamicPseudoType:
69 case t.IsPrimitiveType():
71 case t.IsCollectionType():
73 case t.IsObjectType():
74 attrTypes := t.AttributeTypes()
75 for _, at := range attrTypes {
76 if at.HasDynamicTypes() {
82 elemTypes := t.TupleElementTypes()
83 for _, et := range elemTypes {
84 if et.HasDynamicTypes() {
89 case t.IsCapsuleType():
92 // Should never happen, since above should be exhaustive
93 panic("HasDynamicTypes does not support the given type")