Skip to content

Commit fe1c0b1

Browse files
committed
Support complex structs in storage
Fixes argotorg#636
1 parent db8abce commit fe1c0b1

9 files changed

Lines changed: 1911 additions & 883 deletions

File tree

crates/analyzer/src/db/queries/contracts.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,6 @@ pub fn contract_field_type(
346346
scope.not_yet_implemented("contract field initial value assignment", value_node.span);
347347
}
348348

349-
if matches!(typ, Ok(Type::Struct(Struct { id, .. })) if id.has_complex_fields(db)) {
350-
scope.not_yet_implemented(
351-
"structs in storage aren't yet allowed to contain fields with complex types",
352-
node.span,
353-
);
354-
}
355-
356349
Analysis {
357350
value: typ,
358351
diagnostics: Rc::new(scope.diagnostics),

crates/analyzer/src/namespace/items.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,10 @@ impl StructId {
13421342
matches!(self.field_type(db, name), Some(Ok(FixedSize::Base(_))))
13431343
}
13441344

1345+
pub fn field_index(&self, db: &dyn AnalyzerDb, name: &str) -> Option<usize> {
1346+
self.fields(db).get_index_of(name)
1347+
}
1348+
13451349
pub fn has_complex_fields(&self, db: &dyn AnalyzerDb) -> bool {
13461350
self.fields(db)
13471351
.iter()
@@ -1414,6 +1418,9 @@ impl StructFieldId {
14141418
pub fn typ(&self, db: &dyn AnalyzerDb) -> Result<types::FixedSize, TypeError> {
14151419
db.struct_field_type(*self).value
14161420
}
1421+
pub fn is_base_type(&self, db: &dyn AnalyzerDb) -> bool {
1422+
matches!(self.typ(db), Ok(FixedSize::Base(_)))
1423+
}
14171424
pub fn is_public(&self, db: &dyn AnalyzerDb) -> bool {
14181425
self.data(db).ast.kind.is_pub
14191426
}

0 commit comments

Comments
 (0)