1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

clarify struct declaration and equality

This commit is contained in:
schaeff 2020-10-08 16:19:30 +02:00
parent 954ffb943c
commit 81b3498a04
2 changed files with 13 additions and 61 deletions

View file

@ -373,13 +373,16 @@ impl<'ast> Checker<'ast> {
}
.in_file(module_id),
),
true => {}
true => {
// there should be no entry in the map for this type yet
assert!(state
.types
.entry(module_id.clone())
.or_default()
.insert(declaration.id.to_string(), ty)
.is_none());
}
};
state
.types
.entry(module_id.clone())
.or_default()
.insert(declaration.id.to_string(), ty);
}
Err(e) => errors.extend(e.into_iter().map(|inner| Error {
inner,
@ -4583,60 +4586,6 @@ mod tests {
);
}
#[test]
fn preserve_order() {
// two structs with inverted members are not equal
let module_id = "".into();
let types = HashMap::new();
let declaration0 = StructDefinition {
fields: vec![
StructDefinitionField {
id: "foo",
ty: UnresolvedType::FieldElement.mock(),
}
.mock(),
StructDefinitionField {
id: "bar",
ty: UnresolvedType::Boolean.mock(),
}
.mock(),
],
}
.mock();
let declaration1 = StructDefinition {
fields: vec![
StructDefinitionField {
id: "bar",
ty: UnresolvedType::Boolean.mock(),
}
.mock(),
StructDefinitionField {
id: "foo",
ty: UnresolvedType::FieldElement.mock(),
}
.mock(),
],
}
.mock();
assert_ne!(
Checker::new().check_struct_type_declaration::<Bn128Field>(
"Foo".into(),
declaration0,
&module_id,
&types
),
Checker::new().check_struct_type_declaration::<Bn128Field>(
"Foo".into(),
declaration1,
&module_id,
&types
)
);
}
#[test]
fn duplicate_member_def() {
// definition of a struct with a duplicate member should be rejected

View file

@ -38,7 +38,7 @@ pub struct StructType {
impl PartialEq for StructType {
fn eq(&self, other: &Self) -> bool {
self.canonical_location.eq(&other.canonical_location) && self.members.eq(&other.members)
self.canonical_location.eq(&other.canonical_location)
}
}
@ -304,6 +304,9 @@ impl Type {
match (self, other) {
(Int, FieldElement) | (Int, Uint(..)) => true,
(Array(l), Array(r)) => l.size == r.size && l.ty.can_be_specialized_to(&r.ty),
// types do not come into play for Struct equality, only the canonical location. Hence no inference
// can change anything
(Struct(_), Struct(_)) => false,
_ => false,
}
}