default value behaviour

main
Ziyang Hu 2 years ago
parent dd39abffc2
commit 2633d191ff

@ -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<Value<'a>> {
pub(crate) fn coerce_value<'a>(&self, val: Value<'a>) -> Result<Value<'a>> {
match self {
AttributeTyping::Ref | AttributeTyping::Component => match val {
val @ Value::EnId(_) => Ok(val),

@ -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,

@ -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(),

Loading…
Cancel
Save