Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Dec 4, 2022
1 parent 607b769 commit 0b88a37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 10 additions & 2 deletions rust/candid/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
visitor.visit_map(Compound::new(self, Style::Struct { expect, wire }))?;
Ok(value)
}
(Type::Record(_), Type::Empty) => Err(Error::msg("Cannot decode empty type")),
//(Type::Record(_), Type::Empty) => Err(Error::msg("Cannot decode empty type")),
_ => assert!(false),
}
}
Expand Down Expand Up @@ -837,8 +837,16 @@ impl<'de, 'a> de::MapAccess<'de> for Compound<'a, 'de> {
}
Ordering::Less => {
// by subtyping rules, expect_type can only be opt, reserved or null.
self.de.set_field_name(e.id.clone());
let field = e.id.clone();
self.de.set_field_name(field.clone());
self.de.expect_type = expect.pop_front().unwrap().ty;
check!(
matches!(
self.de.expect_type,
Type::Opt(_) | Type::Reserved | Type::Null
),
format!("field {} is not optional field", field)
);
self.de.wire_type = Type::Reserved;
}
Ordering::Greater => {
Expand Down
5 changes: 1 addition & 4 deletions rust/candid/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ fn test_extra_fields() {

let bytes = encode(&E2::Foo);
test_decode(&bytes, &Some(E2::Foo));
check_error(
|| test_decode(&bytes, &E1::Foo),
"Variant field 3_303_867 not found",
);
test_decode(&bytes, &E1::Foo);
}

#[test]
Expand Down

0 comments on commit 0b88a37

Please sign in to comment.