@@ -114,17 +114,27 @@ func resolveSchema(s *schema.Schema, tr schema.TypeRef, v *value.Value, ah atomH
114114 return handleAtom (a , tr , ah )
115115}
116116
117- func deduceAtom (a schema.Atom , v * value.Value ) schema.Atom {
117+ // deduceAtom determines which of the possible types in atom 'atom' applies to value 'val'.
118+ // If val is of a type allowed by atom, return a copy of atom with all other types set to nil.
119+ // if val is nil, or is not of a type allowed by atom, just return the original atom,
120+ // and validation will fail at a later stage. (with a more useful error)
121+ func deduceAtom (atom schema.Atom , val * value.Value ) schema.Atom {
118122 switch {
119- case v == nil :
120- case v .FloatValue != nil , v .IntValue != nil , v .StringValue != nil , v .BooleanValue != nil :
121- return schema.Atom {Scalar : a .Scalar }
122- case v .ListValue != nil :
123- return schema.Atom {List : a .List }
124- case v .MapValue != nil :
125- return schema.Atom {Map : a .Map }
123+ case val == nil :
124+ case val .FloatValue != nil , val .IntValue != nil , val .StringValue != nil , val .BooleanValue != nil :
125+ if atom .Scalar != nil {
126+ return schema.Atom {Scalar : atom .Scalar }
127+ }
128+ case val .ListValue != nil :
129+ if atom .List != nil {
130+ return schema.Atom {List : atom .List }
131+ }
132+ case val .MapValue != nil :
133+ if atom .Map != nil {
134+ return schema.Atom {Map : atom .Map }
135+ }
126136 }
127- return a
137+ return atom
128138}
129139
130140func handleAtom (a schema.Atom , tr schema.TypeRef , ah atomHandler ) ValidationErrors {
0 commit comments