-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type guard stack order and raise in if statements
- Loading branch information
Showing
7 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
use rue_parser::{AstNode, Block}; | ||
|
||
use crate::{compiler::Compiler, scope::Scope, value::Value, ErrorKind, TypeId}; | ||
use crate::{ | ||
compiler::{block::BlockTerminator, Compiler}, | ||
scope::Scope, | ||
value::Value, | ||
ErrorKind, TypeId, | ||
}; | ||
|
||
impl Compiler<'_> { | ||
pub fn compile_block_expr(&mut self, block: &Block, expected_type: Option<TypeId>) -> Value { | ||
let scope_id = self.db.alloc_scope(Scope::default()); | ||
|
||
self.scope_stack.push(scope_id); | ||
let (value, explicit_return) = self.compile_block(block, expected_type); | ||
let summary = self.compile_block(block, expected_type); | ||
self.scope_stack.pop().unwrap(); | ||
|
||
if explicit_return { | ||
if summary.terminator == BlockTerminator::Return { | ||
self.db | ||
.error(ErrorKind::ExplicitReturnInExpr, block.syntax().text_range()); | ||
} | ||
|
||
value | ||
summary.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
enum Color { | ||
Red, | ||
Green, | ||
Blue, | ||
} | ||
|
||
fun main() -> Int { | ||
let color: Color = Color::Red; | ||
|
||
if color is Color::Green { | ||
raise "Unreachable"; | ||
} | ||
|
||
if color is Color::Blue { | ||
raise "Unreachable"; | ||
} | ||
|
||
assert color is Color::Red; | ||
let red: Color::Red = color; | ||
red as Int | ||
} |