diff --git a/src/data/attr.rs b/src/data/attr.rs index 7b46e1ae..2058a789 100644 --- a/src/data/attr.rs +++ b/src/data/attr.rs @@ -136,7 +136,7 @@ impl AttributeTyping { fn type_err(&self, val: Value) -> TypeError { TypeError::Typing(*self, format!("{:?}", val)) } - fn coerce_value<'a>(&self, val: Value<'a>) -> Result> { + pub(crate) fn coerce_value<'a>(&self, val: Value<'a>) -> Result> { match self { AttributeTyping::Ref | AttributeTyping::Component => match val { val @ Value::EnId(_) => Ok(val), diff --git a/src/preprocess/pull.rs b/src/preprocess/pull.rs index c29505a9..fe2e2522 100644 --- a/src/preprocess/pull.rs +++ b/src/preprocess/pull.rs @@ -126,7 +126,7 @@ impl SessionTx { JsonValue::Object(desc.clone()), "expect boolean or number".to_string(), ) - .into()); + .into()); } recursive = true; } @@ -144,7 +144,7 @@ impl SessionTx { JsonValue::Object(desc.clone()), "expect array".to_string(), ) - .into()); + .into()); } }; } @@ -153,7 +153,7 @@ impl SessionTx { v.into(), "unexpected spec key".to_string(), ) - .into()); + .into()); } } } @@ -169,7 +169,7 @@ impl SessionTx { JsonValue::Object(desc.clone()), "expect target key".to_string(), ) - .into()); + .into()); } let input_kw = input_kw.unwrap(); @@ -188,6 +188,12 @@ impl SessionTx { recursion_depth = max(recursion_depth, 1); } + let default_val = if default_val == Value::Null { + default_val + } else { + attr.val_type.coerce_value(default_val)? + }; + Ok(PullSpec::Attr(AttrPullSpec { attr, default_val, diff --git a/src/transact/pull.rs b/src/transact/pull.rs index 7e3519ef..d450b848 100644 --- a/src/transact/pull.rs +++ b/src/transact/pull.rs @@ -152,7 +152,7 @@ impl SessionTx { collector, recursive_seen, )?; - } else { + } else if spec.default_val != Value::Null { self.pull_attr_collect( spec, spec.default_val.clone(), @@ -372,7 +372,7 @@ impl SessionTx { collector, recursive_seen, )?; - } else { + } else if spec.default_val != Value::Null { self.pull_attr_collect( spec, spec.default_val.clone(),