Skip to content

Commit ebda056

Browse files
committed
Better way to determine constructor call
1 parent cb0f1d8 commit ebda056

File tree

1 file changed

+17
-13
lines changed
  • crates/compilers/src/preprocessor

1 file changed

+17
-13
lines changed

crates/compilers/src/preprocessor/deps.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,23 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
173173

174174
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) -> ControlFlow<Self::BreakValue> {
175175
match &expr.kind {
176-
ExprKind::New(ty) => {
177-
if let TypeKind::Custom(item_id) = ty.kind {
178-
if let Some(contract_id) = item_id.as_contract() {
179-
let name_loc = SourceMapLocation::from_span(self.source_map, ty.span);
180-
let name = &self.src[name_loc.start..name_loc.end];
181-
// TODO: check if there's a better way to determine where constructor call
182-
// ends.
183-
let args_len = self.src[name_loc.end..].split_once(';').unwrap().0.len();
184-
self.collect_dependency(BytecodeDependency {
185-
kind: BytecodeDependencyKind::New(name.to_string(), args_len),
186-
loc: SourceMapLocation::from_span(self.source_map, expr.span),
187-
referenced_contract: contract_id,
188-
});
176+
ExprKind::Call(ty, _, _) => {
177+
if let ExprKind::New(ty_new) = &ty.kind {
178+
if let TypeKind::Custom(item_id) = ty_new.kind {
179+
if let Some(contract_id) = item_id.as_contract() {
180+
let name_loc =
181+
SourceMapLocation::from_span(self.source_map, ty_new.span);
182+
let name = &self.src[name_loc.start..name_loc.end];
183+
let args_len = expr.span.hi() - ty_new.span.hi();
184+
self.collect_dependency(BytecodeDependency {
185+
kind: BytecodeDependencyKind::New(
186+
name.to_string(),
187+
args_len.to_usize(),
188+
),
189+
loc: SourceMapLocation::from_span(self.source_map, ty.span),
190+
referenced_contract: contract_id,
191+
});
192+
}
189193
}
190194
}
191195
}

0 commit comments

Comments
 (0)