Skip to content

Commit

Permalink
fix(sol-hir-lowering): fix statement file
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed May 29, 2024
1 parent 6f1ceb7 commit c529839
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions sol-hir-lowering/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ impl HirLowering<'_, '_> {

let location = self.range(stmt.range());

Stmt::Ask(AskStmt::new(self.db, pattern, expr, location))
Stmt::Ask(AskStmt {
pattern,
value: expr,
location,
})
}

/// Resolves an expression statement.
Expand Down Expand Up @@ -90,7 +94,7 @@ impl HirLowering<'_, '_> {
})
})
})
.unwrap_or_else(|| Expr::call_unit_expr(Location::CallSite, self.db));
.unwrap_or_else(|| Expr::call_unit_expr(Location::CallSite));

let clauses = vec![
MatchArm {
Expand All @@ -107,13 +111,12 @@ impl HirLowering<'_, '_> {

let location = self.range(stmt.range());

Stmt::Downgrade(Expr::Match(MatchExpr::new(
self.db,
/* kind = */ MatchKind::StmtLevel(Box::new(MatchKind::If)),
/* scrutinee = */ scrutinee,
/* clauses = */ clauses,
/* location = */ location,
)))
Stmt::Downgrade(Expr::Match(MatchExpr {
kind: MatchKind::StmtLevel(Box::new(MatchKind::If)),
scrutinee: Box::new(scrutinee),
clauses,
location,
}))
}

/// Resolves a let statement.
Expand All @@ -127,27 +130,30 @@ impl HirLowering<'_, '_> {

let location = self.range(stmt.range());

Stmt::Let(LetStmt::new(self.db, pattern, expr, location))
Stmt::Let(LetStmt {
pattern,
value: expr,
location,
})
}

/// Creates a new block using the current supplied scope.
///
/// It's useful when you already have a well founded scope,
/// and you want to create a block.
pub fn scoped(&mut self, block: sol_syntax::Block, level: HirLevel) -> Block {
let stmts = block
let statements = block
.statements(&mut block.walk())
.flatten()
.filter_map(|stmt| stmt.regular())
.map(|stmt| self.stmt(stmt, level))
.collect();

Block::new(
self.db,
/* statements = */ stmts,
/* location = */ self.range(block.range()),
/* scope = */ self.scope.clone().into(),
)
Block {
statements,
location: self.range(block.range()),
scope: self.scope.clone().into(),
}
}

/// Creates a new scope, and returns the value of the block.
Expand Down

0 comments on commit c529839

Please sign in to comment.