vendor: go get github.com/zclconf/go-cty@v1.5.0

This commit is contained in:
Alisdair McDiarmid 2020-06-11 12:39:11 -04:00
parent 80a4bfbf27
commit 9ef84801a8
7 changed files with 81 additions and 19 deletions

2
go.mod
View File

@ -119,7 +119,7 @@ require (
github.com/xanzy/ssh-agent v0.2.1 github.com/xanzy/ssh-agent v0.2.1
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557 github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557
github.com/zclconf/go-cty v1.4.2 github.com/zclconf/go-cty v1.5.0
github.com/zclconf/go-cty-yaml v1.0.1 github.com/zclconf/go-cty-yaml v1.0.1
go.uber.org/atomic v1.3.2 // indirect go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect go.uber.org/multierr v1.1.0 // indirect

6
go.sum
View File

@ -136,8 +136,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dimchansky/utfbom v1.0.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dimchansky/utfbom v1.0.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4= github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4=
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dnaeon/go-vcr v0.0.0-20180920040454-5637cf3d8a31 h1:Dzuw9GtbmllUqEcoHfScT9YpKFUssSiZ5PgZkIGf/YQ=
github.com/dnaeon/go-vcr v0.0.0-20180920040454-5637cf3d8a31/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/dylanmei/iso8601 v0.1.0 h1:812NGQDBcqquTfH5Yeo7lwR0nzx/cKdsmf3qMjPURUI= github.com/dylanmei/iso8601 v0.1.0 h1:812NGQDBcqquTfH5Yeo7lwR0nzx/cKdsmf3qMjPURUI=
github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ= github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ=
@ -508,8 +506,8 @@ github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6Ut
github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.4.2 h1:GKcsRGjxZnRRlyVk2Y6PyG3fdcn3Pv0D7KT4xyYTLlE= github.com/zclconf/go-cty v1.5.0 h1:U0USwJxGTnUd+dT565f92paYOlRtd201pI7+ZGW36XY=
github.com/zclconf/go-cty v1.4.2/go.mod h1:nHzOclRkoj++EU9ZjSrZvRG0BXIWt8c7loYc0qXAFGQ= github.com/zclconf/go-cty v1.5.0/go.mod h1:nHzOclRkoj++EU9ZjSrZvRG0BXIWt8c7loYc0qXAFGQ=
github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8= github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8=
github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=

View File

@ -156,34 +156,45 @@ func conversionCollectionToMap(ety cty.Type, conv conversion) conversion {
// given tuple type and return a set of the given element type. // given tuple type and return a set of the given element type.
// //
// Will panic if the given tupleType isn't actually a tuple type. // Will panic if the given tupleType isn't actually a tuple type.
func conversionTupleToSet(tupleType cty.Type, listEty cty.Type, unsafe bool) conversion { func conversionTupleToSet(tupleType cty.Type, setEty cty.Type, unsafe bool) conversion {
tupleEtys := tupleType.TupleElementTypes() tupleEtys := tupleType.TupleElementTypes()
if len(tupleEtys) == 0 { if len(tupleEtys) == 0 {
// Empty tuple short-circuit // Empty tuple short-circuit
return func(val cty.Value, path cty.Path) (cty.Value, error) { return func(val cty.Value, path cty.Path) (cty.Value, error) {
return cty.SetValEmpty(listEty), nil return cty.SetValEmpty(setEty), nil
} }
} }
if listEty == cty.DynamicPseudoType { if setEty == cty.DynamicPseudoType {
// This is a special case where the caller wants us to find // This is a special case where the caller wants us to find
// a suitable single type that all elements can convert to, if // a suitable single type that all elements can convert to, if
// possible. // possible.
listEty, _ = unify(tupleEtys, unsafe) setEty, _ = unify(tupleEtys, unsafe)
if listEty == cty.NilType { if setEty == cty.NilType {
return nil return nil
} }
// If the set element type after unification is still the dynamic
// type, the only way this can result in a valid set is if all values
// are of dynamic type
if setEty == cty.DynamicPseudoType {
for _, tupleEty := range tupleEtys {
if !tupleEty.Equals(cty.DynamicPseudoType) {
return nil
}
}
}
} }
elemConvs := make([]conversion, len(tupleEtys)) elemConvs := make([]conversion, len(tupleEtys))
for i, tupleEty := range tupleEtys { for i, tupleEty := range tupleEtys {
if tupleEty.Equals(listEty) { if tupleEty.Equals(setEty) {
// no conversion required // no conversion required
continue continue
} }
elemConvs[i] = getConversion(tupleEty, listEty, unsafe) elemConvs[i] = getConversion(tupleEty, setEty, unsafe)
if elemConvs[i] == nil { if elemConvs[i] == nil {
// If any of our element conversions are impossible, then the our // If any of our element conversions are impossible, then the our
// whole conversion is impossible. // whole conversion is impossible.
@ -244,6 +255,17 @@ func conversionTupleToList(tupleType cty.Type, listEty cty.Type, unsafe bool) co
if listEty == cty.NilType { if listEty == cty.NilType {
return nil return nil
} }
// If the list element type after unification is still the dynamic
// type, the only way this can result in a valid list is if all values
// are of dynamic type
if listEty == cty.DynamicPseudoType {
for _, tupleEty := range tupleEtys {
if !tupleEty.Equals(cty.DynamicPseudoType) {
return nil
}
}
}
} }
elemConvs := make([]conversion, len(tupleEtys)) elemConvs := make([]conversion, len(tupleEtys))

View File

@ -87,7 +87,7 @@ func (t Type) HasDynamicTypes() bool {
case t.IsPrimitiveType(): case t.IsPrimitiveType():
return false return false
case t.IsCollectionType(): case t.IsCollectionType():
return false return t.ElementType().HasDynamicTypes()
case t.IsObjectType(): case t.IsObjectType():
attrTypes := t.AttributeTypes() attrTypes := t.AttributeTypes()
for _, at := range attrTypes { for _, at := range attrTypes {

View File

@ -106,3 +106,37 @@ func (val Value) IsWhollyKnown() bool {
return true return true
} }
} }
// HasWhollyKnownType checks if the value is dynamic, or contains any nested
// DynamicVal. This implies that both the value is not known, and the final
// type may change.
func (val Value) HasWhollyKnownType() bool {
// a null dynamic type is known
if val.IsNull() {
return true
}
// an unknown DynamicPseudoType is a DynamicVal, but we don't want to
// check that value for equality here, since this method is used within the
// equality check.
if !val.IsKnown() && val.ty == DynamicPseudoType {
return false
}
if val.CanIterateElements() {
// if the value is not known, then we can look directly at the internal
// types
if !val.IsKnown() {
return !val.ty.HasDynamicTypes()
}
for it := val.ElementIterator(); it.Next(); {
_, ev := it.Element()
if !ev.HasWhollyKnownType() {
return false
}
}
}
return true
}

View File

@ -133,9 +133,9 @@ func (val Value) Equals(other Value) Value {
case val.IsKnown() && !other.IsKnown(): case val.IsKnown() && !other.IsKnown():
switch { switch {
case val.IsNull(), other.ty.HasDynamicTypes(): case val.IsNull(), other.ty.HasDynamicTypes():
// If known is Null, we need to wait for the unkown value since // If known is Null, we need to wait for the unknown value since
// nulls of any type are equal. // nulls of any type are equal.
// An unkown with a dynamic type compares as unknown, which we need // An unknown with a dynamic type compares as unknown, which we need
// to check before the type comparison below. // to check before the type comparison below.
return UnknownVal(Bool) return UnknownVal(Bool)
case !val.ty.Equals(other.ty): case !val.ty.Equals(other.ty):
@ -148,9 +148,9 @@ func (val Value) Equals(other Value) Value {
case other.IsKnown() && !val.IsKnown(): case other.IsKnown() && !val.IsKnown():
switch { switch {
case other.IsNull(), val.ty.HasDynamicTypes(): case other.IsNull(), val.ty.HasDynamicTypes():
// If known is Null, we need to wait for the unkown value since // If known is Null, we need to wait for the unknown value since
// nulls of any type are equal. // nulls of any type are equal.
// An unkown with a dynamic type compares as unknown, which we need // An unknown with a dynamic type compares as unknown, which we need
// to check before the type comparison below. // to check before the type comparison below.
return UnknownVal(Bool) return UnknownVal(Bool)
case !other.ty.Equals(val.ty): case !other.ty.Equals(val.ty):
@ -171,7 +171,15 @@ func (val Value) Equals(other Value) Value {
return BoolVal(false) return BoolVal(false)
} }
if val.ty.HasDynamicTypes() || other.ty.HasDynamicTypes() { // Check if there are any nested dynamic values making this comparison
// unknown.
if !val.HasWhollyKnownType() || !other.HasWhollyKnownType() {
// Even if we have dynamic values, we can still determine inequality if
// there is no way the types could later conform.
if val.ty.TestConformance(other.ty) != nil && other.ty.TestConformance(val.ty) != nil {
return BoolVal(false)
}
return UnknownVal(Bool) return UnknownVal(Bool)
} }

2
vendor/modules.txt vendored
View File

@ -597,7 +597,7 @@ github.com/xanzy/ssh-agent
# github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557 # github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557
## explicit ## explicit
github.com/xlab/treeprint github.com/xlab/treeprint
# github.com/zclconf/go-cty v1.4.2 # github.com/zclconf/go-cty v1.5.0
## explicit ## explicit
github.com/zclconf/go-cty/cty github.com/zclconf/go-cty/cty
github.com/zclconf/go-cty/cty/convert github.com/zclconf/go-cty/cty/convert