1package cty
2
3// unknownType is the placeholder type used for the sigil value representing
4// "Unknown", to make it unambigiously distinct from any other possible value.
5type unknownType struct {
6}
7
8// unknown is a special value that can be used as the internal value of a
9// Value to create a placeholder for a value that isn't yet known.
10var unknown interface{} = &unknownType{}
11
12// UnknownVal returns an Value that represents an unknown value of the given
13// type. Unknown values can be used to represent a value that is
14// not yet known. Its meaning is undefined in cty, but it could be used by
15// an calling application to allow partial evaluation.
16//
17// Unknown values of any type can be created of any type. All operations on
18// Unknown values themselves return Unknown.
19func UnknownVal(t Type) Value {
20	return Value{
21		ty: t,
22		v:  unknown,
23	}
24}
25
26func (t unknownType) GoString() string {
27	// This is the stringification of our internal unknown marker. The
28	// stringification of the public representation of unknowns is in
29	// Value.GoString.
30	return "cty.unknown"
31}
32
33type pseudoTypeDynamic struct {
34	typeImplSigil
35}
36
37// DynamicPseudoType represents the dynamic pseudo-type.
38//
39// This type can represent situations where a type is not yet known. Its
40// meaning is undefined in cty, but it could be used by a calling
41// application to allow expression type checking with some types not yet known.
42// For example, the application might optimistically permit any operation on
43// values of this type in type checking, allowing a partial type-check result,
44// and then repeat the check when more information is known to get the
45// final, concrete type.
46//
47// It is a pseudo-type because it is used only as a sigil to the calling
48// application. "Unknown" is the only valid value of this pseudo-type, so
49// operations on values of this type will always short-circuit as per
50// the rules for that special value.
51var DynamicPseudoType Type
52
53func (t pseudoTypeDynamic) Equals(other Type) bool {
54	_, ok := other.typeImpl.(pseudoTypeDynamic)
55	return ok
56}
57
58func (t pseudoTypeDynamic) FriendlyName(mode friendlyTypeNameMode) string {
59	switch mode {
60	case friendlyTypeConstraintName:
61		return "any type"
62	default:
63		return "dynamic"
64	}
65}
66
67func (t pseudoTypeDynamic) GoString() string {
68	return "cty.DynamicPseudoType"
69}
70
71// DynamicVal is the only valid value of the pseudo-type dynamic.
72// This value can be used as a placeholder where a value or expression's
73// type and value are both unknown, thus allowing partial evaluation. See
74// the docs for DynamicPseudoType for more information.
75var DynamicVal Value
76
77func init() {
78	DynamicPseudoType = Type{
79		pseudoTypeDynamic{},
80	}
81	DynamicVal = Value{
82		ty: DynamicPseudoType,
83		v:  unknown,
84	}
85}
86