Skip to content

Commit

Permalink
Forbid explicit return in if expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Apr 16, 2024
1 parent 06e5d7e commit bba3b66
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions crates/rue-compiler/src/lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,15 +1326,9 @@ impl<'a> Lowerer<'a> {
self.type_guards.push(condition.then_guards());
}

let then_block = if_expr.then_block().map(|then_block| {
let scope_id = self.db.alloc_scope(Scope::default());

self.scope_stack.push(scope_id);
let value = self.compile_block(then_block, expected_type).0;
self.scope_stack.pop().unwrap();

value
});
let then_block = if_expr
.then_block()
.map(|then_block| self.compile_block_expr(then_block, expected_type));

if condition.is_some() {
self.type_guards.pop().unwrap();
Expand All @@ -1347,15 +1341,9 @@ impl<'a> Lowerer<'a> {
let expected_type =
expected_type.or_else(|| then_block.as_ref().map(|then_block| then_block.ty()));

let else_block = if_expr.else_block().map(|else_block| {
let scope_id = self.db.alloc_scope(Scope::default());

self.scope_stack.push(scope_id);
let value = self.compile_block(else_block, expected_type).0;
self.scope_stack.pop().unwrap();

value
});
let else_block = if_expr
.else_block()
.map(|else_block| self.compile_block_expr(else_block, expected_type));

if condition.is_some() {
self.type_guards.pop().unwrap();
Expand Down

0 comments on commit bba3b66

Please sign in to comment.