]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/zclconf/go-cty/cty/type.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / zclconf / go-cty / cty / type.go
1 package cty
2
3 // Type represents value types within the type system.
4 //
5 // This is a closed interface type, meaning that only the concrete
6 // implementations provided within this package are considered valid.
7 type Type struct {
8 typeImpl
9 }
10
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
15
16 // Equals returns true if the other given Type exactly equals the
17 // receiver Type.
18 Equals(other Type) bool
19
20 // FriendlyName returns a human-friendly *English* name for the given
21 // type.
22 FriendlyName() string
23
24 // GoString implements the GoStringer interface from package fmt.
25 GoString() string
26 }
27
28 // Base implementation of Type to embed into concrete implementations
29 // to signal that they are implementations of Type.
30 type typeImplSigil struct{}
31
32 func (t typeImplSigil) isTypeImpl() typeImplSigil {
33 return typeImplSigil{}
34 }
35
36 // Equals returns true if the other given Type exactly equals the receiver
37 // type.
38 func (t Type) Equals(other Type) bool {
39 return t.typeImpl.Equals(other)
40 }
41
42 // FriendlyName returns a human-friendly *English* name for the given type.
43 func (t Type) FriendlyName() string {
44 return t.typeImpl.FriendlyName()
45 }
46
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 {
51 return "cty.NilType"
52 }
53
54 return t.typeImpl.GoString()
55 }
56
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.
60 var NilType = Type{}
61
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 {
66 switch {
67 case t == DynamicPseudoType:
68 return true
69 case t.IsPrimitiveType():
70 return false
71 case t.IsCollectionType():
72 return false
73 case t.IsObjectType():
74 attrTypes := t.AttributeTypes()
75 for _, at := range attrTypes {
76 if at.HasDynamicTypes() {
77 return true
78 }
79 }
80 return false
81 case t.IsTupleType():
82 elemTypes := t.TupleElementTypes()
83 for _, et := range elemTypes {
84 if et.HasDynamicTypes() {
85 return true
86 }
87 }
88 return false
89 case t.IsCapsuleType():
90 return false
91 default:
92 // Should never happen, since above should be exhaustive
93 panic("HasDynamicTypes does not support the given type")
94 }
95 }