difftreelog
fix disallow field duplicates
in: master
5 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -63,6 +63,8 @@
#[error("field name should be string, got {0}")]
FieldMustBeStringGot(ValType),
+ #[error("duplicate field name: {0}")]
+ DuplicateFieldName(IStr),
#[error("attempted to index array with string {0}")]
AttemptedIndexAnArrayWithString(IStr),
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -298,7 +298,7 @@
context_creator: context_creator.clone(),
value: value.clone(),
name,
- })));
+ })))?;
}
Member::Field(FieldMember {
name,
@@ -341,7 +341,7 @@
value: value.clone(),
params: params.clone(),
name,
- })));
+ })))?;
}
Member::BindStmt(_) => {}
Member::AssertStmt(stmt) => {
@@ -424,7 +424,7 @@
.bindable(TraceBox(Box::new(ObjCompBinding {
context: ctx,
value: obj.value.clone(),
- })));
+ })))?;
}
v => throw!(FieldMustBeStringGot(v.value_type())),
}
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -68,7 +68,7 @@
Value::Object(o) => {
let mut builder = ObjValueBuilder::with_capacity(o.len());
for (k, v) in o {
- builder.member((k as &str).into()).value(v.try_into()?);
+ builder.member((k as &str).into()).value(v.try_into()?)?;
}
Self::Obj(builder.build())
}
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth1use crate::function::CallLocation;1use crate::gc::{GcHashMap, GcHashSet, TraceBox};2use crate::gc::{GcHashMap, GcHashSet, TraceBox};2use crate::operator::evaluate_add_op;3use crate::operator::evaluate_add_op;4use crate::push_frame;3use crate::{cc_ptr_eq, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal, Result, Val};5use crate::{6 cc_ptr_eq, error::Error::*, throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal,7 Result, Val,8};4use gcmodule::{Cc, Trace, Weak};9use gcmodule::{Cc, Trace, Weak};5use jrsonnet_interner::IStr;10use jrsonnet_interner::IStr;373 self.location = Some(location);378 self.location = Some(location);374 self379 self375 }380 }376 pub fn value(self, value: Val) -> &'v mut ObjValueBuilder {381 pub fn value(self, value: Val) -> Result<()> {377 self.binding(LazyBinding::Bound(LazyVal::new_resolved(value)))382 self.binding(LazyBinding::Bound(LazyVal::new_resolved(value)))378 }383 }379 pub fn bindable(self, bindable: TraceBox<dyn Bindable>) -> &'v mut ObjValueBuilder {384 pub fn bindable(self, bindable: TraceBox<dyn Bindable>) -> Result<()> {380 self.binding(LazyBinding::Bindable(Cc::new(bindable)))385 self.binding(LazyBinding::Bindable(Cc::new(bindable)))381 }386 }382 pub fn binding(self, binding: LazyBinding) -> &'v mut ObjValueBuilder {387 pub fn binding(self, binding: LazyBinding) -> Result<()> {383 self.value.map.insert(388 let old = self.value.map.insert(384 self.name,389 self.name.clone(),385 ObjMember {390 ObjMember {386 add: self.add,391 add: self.add,387 visibility: self.visibility,392 visibility: self.visibility,388 invoke: binding,393 invoke: binding,389 location: self.location,394 location: self.location.clone(),390 },395 },391 );396 );397 if old.is_some() {398 push_frame(399 CallLocation(self.location.as_ref()),392 self.value400 || format!("field <{}> initializtion", self.name.clone()),401 || throw!(DuplicateFieldName(self.name.clone())),402 )?403 }404 Ok(())393 }405 }394}406}395407crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -459,12 +459,12 @@
if self.is_option() {
quote! {
if let Some(value) = self.#ident {
- out.member(#name.into()).value(value.try_into()?);
+ out.member(#name.into()).value(value.try_into()?)?;
}
}
} else {
quote! {
- out.member(#name.into()).value(self.#ident.try_into()?);
+ out.member(#name.into()).value(self.#ident.try_into()?)?;
}
}
} else if self.is_option() {